Weird File Open Behavior After Windows 11 Upgrade

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
73,970
Office Version
  1. 365
Platform
  1. Windows
I wrote some VBA code years ago for work that opens a bunch of files and runs some comparisons. The files have the same prefix every week, but different time stamps.
So this is the code the VBA code uses to open the files (first file):
VBA Code:
    Dim fName As String
    fName = "C:\TEMP\Macros\Test\CMDB Server Report_*.xlsx"
    Workbooks.Open Filename:=fName
(I should note, that there will only ever be one file in the folder matching the desired prefix)

This has worked for them for years. Now, they have some updates they want me to make. When I try to run this code (which works for them) on my computer, I get the following error:
1693573812518.png


If I run this version of the code, with the exact file name, it works as expected.
VBA Code:
    Dim fName As String
    fName = "C:\TEMP\Macros\Test\CMDB Server Report_20230901_0637.xlsx"
    Workbooks.Open Filename:=fName
however, since the date/time stamp changes every week, I cannot do that.

I don't understand why the original code is no longer working on my computer. The only thing of note I can think of is I upgraded to Windows 11 recently.
Perhaps some system setting changed, messing things up? Anyone have any ideas?
 
Pff ok, thanks for testing. Still weird o_O
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Pff ok, thanks for testing. Still weird o_O
Yeah, I agree.

It is weird that I did need to update the code to get the Excel files to work, but not the CSV files. They were all working the same way originally.
As long as everything works, I guess!

So the solution for this particular issue was a combination of 6StringJazzer's post (post #2) and Rory's post (post #5).
 
Upvote 0
Dir onlly returns the file name, not path, so you should include the path in the Workbooks.Open with fName
Y'know, I forgot that but it worked just in my case probably because the folder the code was in was also the folder containing the file I was searching for. Poor testing.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
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