Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to avoid opening an empty workbook every time I open a file? Nick Papadakis Setting up and Configuration of Excel 2 February 12th 06 11:55 AM
excel VBA problem - setting workbook as variable & opening/re-opening safe Excel Programming 1 August 20th 04 12:22 AM
opening or activating another workbook file Paul James[_4_] Excel Programming 8 January 2nd 04 12:37 AM
How to make the opening of a workbook conditional upon the opening of another workbook Marcello do Guzman Excel Programming 1 December 16th 03 06:09 AM
How to make opening of workbook conditional of opening of another workbook turk5555[_2_] Excel Programming 2 December 15th 03 11:07 PM


All times are GMT +1. The time now is 03:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"