Hi - I am trying to write a macro that will open a workbook if it exists. The workbook that will be opening always starts with the same characters, but the end of the file name varies based on date. I was trying to include a "wildcard" character to account for this but I keep getting a run time error 1004 saying the file does not exist. Would someone be able to verify the code below and see where I am maybe going wrong?
Thank you.
Thank you.
Code:
Sub BusinessObjectsRetrieve()
Dim strFile As String
Dim WB As Workbook
Dim dirFile As String
strFile = "AutoRunQuery_" & "*"
dirFile = "C:\Users\user\Documents\AutoRunQuery*.xlsx"
If Len(Dir(dirFile)) = 0 Then
MsgBox "File does not exist!"
Else
Set WB = Workbooks.Open(dirFile)
End If
End Sub