Old VBA Code No Longer Working

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
73,970
Office Version
  1. 365
Platform
  1. 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:
VBA Code:
'   Open data file
    Dim dFile As String
    dFile = "C:\Temp\Macros\Data\Assets - All*.xlsx"
    Workbooks.Open Filename:=dFile
(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.

1700250989030.png


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"
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
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Lots of posts here and there saying you can't do it this way. It's my experience that application or Windows updates tend to make code that worked suddenly not work. The usual solution is to fix the code because it was never quite correct - people just got away with it until they didn't.
 
Upvote 0
Solution
Lots of posts here and there saying you can't do it this way. It's my experience that application or Windows updates tend to make code that worked suddenly not work. The usual solution is to fix the code because it was never quite correct - people just got away with it until they didn't.
Thanks, that fixed it!

To be honest, I was a little surprised that the original code worked in the first place...
 
Upvote 0
Glad I could point you in the right direction & thanks for the recognition.
I've seen several issues posted in AccessForums.net about old code no longer working and every one of them was malformed code that they somehow got away with for a time. The usual trigger was that the application had been updated, plus it seemed that M$ introduced a new bug every time there was an update. It's why I turned updates off for Office apps.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top