Using a cell value as a string in VBA

SpearC1993

New Member
Joined
Jan 22, 2016
Messages
5
Hello all,

Back again for another question!

Can I use a cell value in VBA to open a file for example:

Set January = Workbooks.Open("C:\Users\"CELL A1 HERE".xls") <- this is a guess

In my work sheet have a cell like such

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]January_3047[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


The result would then be that the macro would open an excel in the location "C:\Users\January_3047.xls". At the moment I have statically written these in but I dont want to write over this code every month.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this, adjusting 'Sheetname' to the name of the sheet where A1 holds your bookname.
Code:
Dim MyBook As String
MyBook = Sheets("Sheetname").Range("A1").Value
Set January = Workbooks.Open("C:\Users\" & MyBook & ".xls")
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,705
Members
453,748
Latest member
akhtarf3

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