Tanyaann1995
Board Regular
- Joined
- Mar 24, 2021
- Messages
- 62
- Office Version
- 2016
- Platform
- Windows
Hi,
I want to open only Excel files in a folder and the below is the code which I'm using currently. But, I get an error message: "Compile Error: User defined type not defined" and the "Dim FSO" line gets highlighted.
I want to open only Excel files in a folder and the below is the code which I'm using currently. But, I get an error message: "Compile Error: User defined type not defined" and the "Dim FSO" line gets highlighted.
VBA Code:
Dim FSO As Scripting.FileSystemObject, folder As Scripting.folder, file As Scripting.file
Set FSO = CreateObject("Scripting.FileSystemObject")
a = wb.path
Set folder = FSO.GetFolder(a)
For Each file In folder.Files
If Right(file, 5) = ".xlsx" Then
Workbooks.Open file
Else
MsgBox ("No Datasheets found in Sizing folder")
End If
Next file