indi visual
Member
The following code beneath works if the full path is entered.
However, I am attempting to use a wildcard for the folder name to access an xml file.
Please see '''the last five characters could be anything in the code notes below
I've tried both "?????" and "*" to no avail.
Any ideas on what I'm doing wrong?
Sub Get_File_Using_Folder_Wildcard_Name()
'--------------------------------------------
Application.ScreenUpdating = False
'--------------------------------------------
Dim CheckFile As String
Dim MyPath As String
Dim VariableNumberPath As String
'--------------------------------------------
MyPath = "C:UsersAnonymousDesktop" & VariableNumberPath
VariableNumberPath = "47000?????" & "" '''the last five characters could be anything
'--------------------------------------------
CheckFile = Dir(MyPath & "" & "*.xml") ' filter .xml files
'- no files
If CheckFile = "" Then
MsgBox ("No .xml files in " & MyPath)
End If
'- loop through files in folder
Do While CheckFile <> ""
rsp = MsgBox("Do you wish to open " & CheckFile & " ?", vbYesNoCancel)
If rsp = vbCancel Then End
If rsp = vbYes Then
Workbooks.Open Filename:=MyPath & CheckFile
End If
CheckFile = Dir ' Get next file
Loop
'--------------------------------------------
Application.ScreenUpdating = True
'--------------------------------------------
End Sub
However, I am attempting to use a wildcard for the folder name to access an xml file.
Please see '''the last five characters could be anything in the code notes below
I've tried both "?????" and "*" to no avail.
Any ideas on what I'm doing wrong?
Sub Get_File_Using_Folder_Wildcard_Name()
'--------------------------------------------
Application.ScreenUpdating = False
'--------------------------------------------
Dim CheckFile As String
Dim MyPath As String
Dim VariableNumberPath As String
'--------------------------------------------
MyPath = "C:UsersAnonymousDesktop" & VariableNumberPath
VariableNumberPath = "47000?????" & "" '''the last five characters could be anything
'--------------------------------------------
CheckFile = Dir(MyPath & "" & "*.xml") ' filter .xml files
'- no files
If CheckFile = "" Then
MsgBox ("No .xml files in " & MyPath)
End If
'- loop through files in folder
Do While CheckFile <> ""
rsp = MsgBox("Do you wish to open " & CheckFile & " ?", vbYesNoCancel)
If rsp = vbCancel Then End
If rsp = vbYes Then
Workbooks.Open Filename:=MyPath & CheckFile
End If
CheckFile = Dir ' Get next file
Loop
'--------------------------------------------
Application.ScreenUpdating = True
'--------------------------------------------
End Sub