juancarlos1
New Member
- Joined
- Sep 22, 2021
- Messages
- 8
- Office Version
- 365
Hello!
There is the need to open the first and only the first Excel file present in a specific folder.
I am having some trouble using the Dir function with a relative reference.
This code is working when the full path is there placed, but the reference must be relative:
Bad file name or number is the error returned.
Can anyone advise here?
Regards!
There is the need to open the first and only the first Excel file present in a specific folder.
I am having some trouble using the Dir function with a relative reference.
This code is working when the full path is there placed, but the reference must be relative:
VBA Code:
Dim FileName As String
FileName = VBA.FileSystem.Dir(ThisWorkbook.Path & "\Export files to process\*.xlsx")
If FileName = VBA.Constants.vbNullString Then
MsgBox "No file found in the folder"
Else
Workbooks.Open ThisWorkbook.Path & "\Export files to process\" & FileName
End If
Bad file name or number is the error returned.
Can anyone advise here?
Regards!