Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Get calling workbook path?
Hi all,
I have a solution where a set a data workbooks (with no VBA code) all referring (with Tools References) to a code workbook (full of code). So when a data workbook opens, it calls the code workbook, and the Auto_Open() procedure in the code workbook is run. I wonder if it's possible for Auto_Open() to know which file called the code workbook? Gustaf |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Get calling workbook path?
Gustaf,
If you have a naming convention, you could check all the open workbooks to see which workbook has that type of name. You could also check the references of the active workbook: Sub TryNow() Dim myRef As Reference For Each myRef In ActiveWorkbook.VBProject.References If myRef.Name = "CalledVBAProjName" Then MsgBox "I'm being called by " & ActiveWorkbook.FullName End If Next myRef End Sub You could also cycle through the open workbooks if the activeworkbook is changed by the act of the code workbook being opened (I would hide that workbook...) HTH, Bernie MS Excel MVP "Gustaf" wrote in message ... Hi all, I have a solution where a set a data workbooks (with no VBA code) all referring (with Tools References) to a code workbook (full of code). So when a data workbook opens, it calls the code workbook, and the Auto_Open() procedure in the code workbook is run. I wonder if it's possible for Auto_Open() to know which file called the code workbook? Gustaf |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Get calling workbook path?
Thank you Bernie,
Your code is quite useful, even though it's not fully watertight for my purpose. There is a naming convention, but there may be several data workbooks open at the same time, all of them using the same prefix in the filename. I'm aware of the ActiveWorkbook and ThisWorkbook objects in the API, and I wonder if maybe ActiveWorkbook would still point to the calling workbook in Auto_Open(). I haven't explicitly activated the code workbook after all. I will try this tomorrow, to see how it turns out. Gustaf -- Bernie Deitrick wrote: Gustaf, If you have a naming convention, you could check all the open workbooks to see which workbook has that type of name. You could also check the references of the active workbook: Sub TryNow() Dim myRef As Reference For Each myRef In ActiveWorkbook.VBProject.References If myRef.Name = "CalledVBAProjName" Then MsgBox "I'm being called by " & ActiveWorkbook.FullName End If Next myRef End Sub You could also cycle through the open workbooks if the activeworkbook is changed by the act of the code workbook being opened (I would hide that workbook...) HTH, Bernie MS Excel MVP "Gustaf" wrote in message ... Hi all, I have a solution where a set a data workbooks (with no VBA code) all referring (with Tools References) to a code workbook (full of code). So when a data workbook opens, it calls the code workbook, and the Auto_Open() procedure in the code workbook is run. I wonder if it's possible for Auto_Open() to know which file called the code workbook? Gustaf |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Calling open workbook from another workbook | Excel Programming | |||
calling sub from other workbook | Excel Programming | |||
Passing calling workbook name to called workbook | Excel Programming | |||
Calling another workbook | Excel Programming | |||
Reference code in another workbook from a calling workbook | Excel Programming |