Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default 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
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
Calling open workbook from another workbook Merlynsdad Excel Programming 8 October 20th 09 04:07 PM
calling sub from other workbook pls123 Excel Programming 1 May 2nd 09 09:39 PM
Passing calling workbook name to called workbook DRK Excel Programming 7 May 6th 06 01:34 AM
Calling another workbook Patrick Simonds Excel Programming 5 April 3rd 06 06:29 PM
Reference code in another workbook from a calling workbook Datasort Excel Programming 1 January 4th 05 01:13 AM


All times are GMT +1. The time now is 12:01 AM.

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"