简体   繁体   中英

Unable to open a file using wild card through VBA, there will be only 1 file with that file name with changing dates

I want to open a file "Account Master mmddyy.xls" which gets saved at a particular path, every month only date and month changes. How can I open the file with wild card using "Account Master" as that will be consistent. Only 1 file will be saved at this location with similar file name.

I tried this but it didn't work.

Sub open_file()

    Workbooks.Open Filename:="C:\Users\Desktop\WORK\Account Master*"

End Sub

Try this:

Sub open_file()
Dim sFilename As String
    sFilename = Dir("C:\Users\Desktop\WORK\Account Master*", vbArchive)
    Workbooks.Open Filename:=sFilename
end sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM