VBA Excel opening a file

rjenkins5

Board Regular
Joined
Oct 11, 2007
Messages
73
Hi I am trying to open up a workbook based on a cell path.

How do I do this. The reason I have it in a cell is because part of the file name will change each month.

Thanks

Ross
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If the path is in A1 and the filename is in sFilename, then this should do it:-
Code:
Workbooks.Open (Range("A1").Value & "\" & sFilename)

If the filename is in A1 and the path is in sFolder, then this should do it:-
Code:
Workbooks.Open (sFolder & "\" & Range("A1").Value)
 
Last edited:
Upvote 0
If the folder and/or the filename change each month in a deterministic sort of way - like maybe they're based on the date - then you could do away with having the value in a cell at all.

For example, if the filename is always in the format Timesheet for August 2011.xls, you could do:-
Code:
Workbooks.Open (sPath & "\Timesheet for " & Format(Now(), "mmmm yyyy") & ".xls)

If it's for a previous month, it's possible to subtract a month from the date without too much difficulty.
 
Upvote 0
Hi thanks for this. If file path and name are together I just do the following?

Workbooks.Open (Range("A1").Value)

Thanks

Ross
 
Upvote 0
thumbs-up.jpg
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

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