Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening another workbook file
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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening another workbook file
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 '<<============= --- Regards, Norman "J. Barrington at" <"jbarrington comcast: net" wrote in message . .. 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? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening another workbook file
Thank you Norman!
That worked and your example pointed out what I was doing wrong in my efforts. Thanks John Norman Jones wrote: 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 '<<============= --- Regards, Norman "J. Barrington at" <"jbarrington comcast: net" wrote in message . .. 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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to avoid opening an empty workbook every time I open a file? | Setting up and Configuration of Excel | |||
excel VBA problem - setting workbook as variable & opening/re-opening | Excel Programming | |||
opening or activating another workbook file | Excel Programming | |||
How to make the opening of a workbook conditional upon the opening of another workbook | Excel Programming | |||
How to make opening of workbook conditional of opening of another workbook | Excel Programming |