Joe4
MrExcel MVP, Junior Admin
- Joined
- Aug 1, 2002
- Messages
- 73,970
- Office Version
- 365
- Platform
- Windows
Last year, I wrote some VBA code for another department. One of the steps was to import a bunch of files based on their file prefix (most of the files have date stamps built into their names).
An example of one of those sections looks like this:
(note that there will always be exactly one file in this folder with the "Assets - All" prefix.
It ran fine, and the department has been using it for the last year. Now, they have some adjustments to make to the code.
Now, when I try to run it, I am getting this error message.
I confirmed that there exactly one file in this folder with this prefix (and file extension), and it is not currently open.
If I rename it to "C:\Temp\Macros\Data\Assets - All.xlsx" and then update the line of VBA code to say:
if will successfully open the file.
So it appears that something changed where it no longer likes the wildcard in the file name (though it worked just fine in the past with that in there).
The only thing that changed since I worked on this last year was I recently got a new computer. Both ran Excel 365, but I upgraded from Windows 10 to Windows 11.
And yes, when you view the files in File Explorer, it does show the file extension.
Any ideas what may be going on and why this stop working?
Thanks
An example of one of those sections looks like this:
VBA Code:
' Open data file
Dim dFile As String
dFile = "C:\Temp\Macros\Data\Assets - All*.xlsx"
Workbooks.Open Filename:=dFile
It ran fine, and the department has been using it for the last year. Now, they have some adjustments to make to the code.
Now, when I try to run it, I am getting this error message.
I confirmed that there exactly one file in this folder with this prefix (and file extension), and it is not currently open.
If I rename it to "C:\Temp\Macros\Data\Assets - All.xlsx" and then update the line of VBA code to say:
VBA Code:
dFile = "C:\Temp\Macros\Data\Assets - All.xlsx"
So it appears that something changed where it no longer likes the wildcard in the file name (though it worked just fine in the past with that in there).
The only thing that changed since I worked on this last year was I recently got a new computer. Both ran Excel 365, but I upgraded from Windows 10 to Windows 11.
And yes, when you view the files in File Explorer, it does show the file extension.
Any ideas what may be going on and why this stop working?
Thanks