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

A
1January_3047

<tbody>
</tbody>


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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,221,519
Messages
6,160,285
Members
451,635
Latest member
nithchun

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