Error when using Workbooks.Open with the * character

VBAam

New Member
Joined
Aug 1, 2017
Messages
3
Hi

I have been running a code which opens an excel file whose name changes each day. The naming convention of the file is essential "Input file-[date]-[time].xlsx".

Given the time can vary, I have used the * character to specify the file name:

filesource_path = "N:\Input files"
filesource_date = Format(Date, "yyyy-mm-dd")
filesource_name = filesource_path & "Input file-" & filesource_date & "*.xlsx"

Dim sourcewb As Workbook
Set sourcewb = Workbooks.Open(filesource_name)

This runs absolutely fine when the file is save in a folder on the network drive (N:). However, I just tried to change the path to a local drive e.g. "C:\Input files" and saved a copy of the file there but then I encounter the run-time error 1004 which says "Sorry, we couldn't find C:\Input files\Input file-2017-08-01*.xlsx."

Does anyone know why this is happening?

Thanks!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Re: Error when using Workbooks.Open with the * character - Help!

Hi

I have been running a code which opens an excel file whose name changes each day. The naming convention of the file is essential "Input file-[date]-[time].xlsx".

Given the time can vary, I have used the * character to specify the file name:

filesource_path = "N:\Input files"
filesource_date = Format(Date, "yyyy-mm-dd")
filesource_name = filesource_path & "Input file-" & filesource_date & "*.xlsx"

Dim sourcewb As Workbook
Set sourcewb = Workbooks.Open(filesource_name)

This runs absolutely fine when the file is save in a folder on the network drive (N:). However, I just tried to change the path to a local drive e.g. "C:\Input files" and saved a copy of the file there but then I encounter the run-time error 1004 which says "Sorry, we couldn't find C:\Input files\Input file-2017-08-01*.xlsx."

Does anyone know why this is happening?

Thanks!

Help!
 
Upvote 0
Re: Error when using Workbooks.Open with the * character - Help!

Thanks Nine Zero. The odd thing is that the asterisk works when the file is saved in some locations but not others.

The bottom of that thread mentions something about UNC paths - maybe this has something to do with it?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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