Opening another workbook file

J

J. Barrington

The line below seems to open the file ”book1.xls”:
Workbooks.Open “C:\famous\book1.xls”

I will need to easily change the path location of a workbook, or change
the workbook name without going back into the routine to do it, nor
having else go to the routine and change it too.

What I want is to have one cell that has the path location
A1 = C:\famous\
another cell that has the filename
A2 = book1.xls
and then have a code that can refer to those two cell locations for
opening another workbook.

I tried to adapt the code from the top with some cell references, but
without success. How can this be done?
 
N

Norman Jones

Hi J,

Try something like:

'=============>>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim sStr As String
Dim sStr2 As String

Set WB = ThisWorkbook
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE
sStr = SH.Range("A1").Value
sStr2 = SH.Range("A2").Value
Set WB = Workbooks.Open(Filename:=sStr & sStr2)
End Sub
'<<=============
 
J

jbarrington

Thank you Norman!
That worked and your example pointed out what I was doing wrong in my
efforts.

Thanks
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top