Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find WkBk Path, Then use this path to open another WkBk in Subfold
Hi folks, I'm really hoping someone can help me with this question, it has
two parts. I have a folder called 'MyProgram', and within it I have a folder called 'Data'. In the MyProgram folder I have the currently active workbook, 'Book1.xls', and in the Data folder I have 'Book2.xls'. Firstly I need to locate where the currently active workbook Book1.xls is on the current hard drive? e.g: C:\Program Files\MyFolder...or D:\Example\The Program\MyFolder etc Then I need to adapt and use this information in a Workbooks.Open statement to open Book2.xls in the Data subfolder? Any help is much appreciated. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find WkBk Path, Then use this path to open another WkBk in Subfold
Sub WhereAmI()
MsgBox (ThisWorkbook.Path) End Sub -- Gary''s Student - gsnu200781 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find WkBk Path, Then use this path to open another WkBk in Sub
Thank GS,
So If I put into my auto_open macro: Location = (ThisWorkbook.Path) Where the path is C:\Program Files\Test\MyProgram\Book1.xls How do I then use the variable 'Location' to open the workbook Book2.xls in C:\Program Files\Test\MyProgram\Data\. Something like: Workbooks.Open ($ Location $ "\" Data\Book2.xls) ??? Thanks for any more advice? "Gary''s Student" wrote: Sub WhereAmI() MsgBox (ThisWorkbook.Path) End Sub -- Gary''s Student - gsnu200781 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find WkBk Path, Then use this path to open another WkBk in Sub
thisworkbook.path
will not include the filename. It'll return something like: C:\Program Files\Test\MyProgram So maybe you could use: Dim myFileName as string dim wkbk2 as workbook myfilename = thisworkbook.path & "\data\book2.xls" set wkbk2 = workbooks.open(filename:=myfilename) dim wrote: Thank GS, So If I put into my auto_open macro: Location = (ThisWorkbook.Path) Where the path is C:\Program Files\Test\MyProgram\Book1.xls How do I then use the variable 'Location' to open the workbook Book2.xls in C:\Program Files\Test\MyProgram\Data\. Something like: Workbooks.Open ($ Location $ "\" Data\Book2.xls) ??? Thanks for any more advice? "Gary''s Student" wrote: Sub WhereAmI() MsgBox (ThisWorkbook.Path) End Sub -- Gary''s Student - gsnu200781 -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find WkBk Path, Then use this path to open another WkBk in Sub
Thanks Dave, that worked a charm, but I simplified it slightly for my needs.
Workbooks.Open (ThisWorkbook.Path & "\Data\Book2.xls") Cheers. I appreciate it. :-) "Dave Peterson" wrote: thisworkbook.path will not include the filename. It'll return something like: C:\Program Files\Test\MyProgram So maybe you could use: Dim myFileName as string dim wkbk2 as workbook myfilename = thisworkbook.path & "\data\book2.xls" set wkbk2 = workbooks.open(filename:=myfilename) dim wrote: Thank GS, So If I put into my auto_open macro: Location = (ThisWorkbook.Path) Where the path is C:\Program Files\Test\MyProgram\Book1.xls How do I then use the variable 'Location' to open the workbook Book2.xls in C:\Program Files\Test\MyProgram\Data\. Something like: Workbooks.Open ($ Location $ "\" Data\Book2.xls) ??? Thanks for any more advice? "Gary''s Student" wrote: Sub WhereAmI() MsgBox (ThisWorkbook.Path) End Sub -- Gary''s Student - gsnu200781 -- Dave Peterson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find WkBk Path, Then use this path to open another WkBk in Sub
You don't even need the ()'s:
Workbooks.Open ThisWorkbook.Path & "\Data\Book2.xls" dim wrote: Thanks Dave, that worked a charm, but I simplified it slightly for my needs. Workbooks.Open (ThisWorkbook.Path & "\Data\Book2.xls") Cheers. I appreciate it. :-) "Dave Peterson" wrote: thisworkbook.path will not include the filename. It'll return something like: C:\Program Files\Test\MyProgram So maybe you could use: Dim myFileName as string dim wkbk2 as workbook myfilename = thisworkbook.path & "\data\book2.xls" set wkbk2 = workbooks.open(filename:=myfilename) dim wrote: Thank GS, So If I put into my auto_open macro: Location = (ThisWorkbook.Path) Where the path is C:\Program Files\Test\MyProgram\Book1.xls How do I then use the variable 'Location' to open the workbook Book2.xls in C:\Program Files\Test\MyProgram\Data\. Something like: Workbooks.Open ($ Location $ "\" Data\Book2.xls) ??? Thanks for any more advice? "Gary''s Student" wrote: Sub WhereAmI() MsgBox (ThisWorkbook.Path) End Sub -- Gary''s Student - gsnu200781 -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Creating a Hyperlink from 1 WKBK to open another WKBK and activate | Excel Programming | |||
run a procedure in 1 wkbk from another wkbk | Excel Programming | |||
Keep original wkbk open after SaveAs? | Excel Programming | |||
Open Object as Wkbk opens | Excel Programming | |||
Error Message Wkbk Open | Excel Programming |