VBA to Open workbook with part file name

hblbs

Board Regular
Joined
Mar 18, 2009
Messages
184
Hello

I have a file name "Work_outstanding_010411.xls". I am trying to open the workbook with VBA using only part of the file name, see below.

Code:
Workbooks.Open Filename:="C:\Work\Work_outstanding_*"

But I keep getting error saying the workbook can not be found.

Is it possible to open a workbook using the beginning of the file name only as opposed to the entire name? The beginning is always the same however the date only changes.

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I think you will need to add the & ".xls" to the end as you need to reference the file extension.
 
Upvote 0
Hello thanks for the reply, even with the file extension I get the same error message.

Any help is appreciated.

Code:
Workbooks.Open Filename:="C:\Work\Work_outstanding_*.xls"
 
Upvote 0
Hello thanks for the reply, even with the file extension I get the same error message.

Any help is appreciated.

Code:
Workbooks.Open Filename:="C:\Work\Work_outstanding_*.xls"

Change the end as indicated below:

Workbooks.Open Filename:="C:\Work\Work_outstanding_*" & ".xls"
</PRE>
 
Upvote 0
Hello I have tried the following but unfortunately the same error is given.

Code:
Workbooks.Open Filename:="C:\Work\Work_outstanding_*" & ".xls"
 
Upvote 0
Hello I have tried the following but unfortunately the same error is given.

Code:
Workbooks.Open Filename:="C:\Work\Work_outstanding_*" & ".xls"

The number of * characters must equal the number of expected characters to follow _outstanding_. For example, if it were a date that was following in mm_dd_yy format, you would enter ********, or 8 *.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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