• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Get File Using Wildcard For Folder Name

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
 
Back
Top