Excel 2003 VBA - reference to xls-File the current macro belongs to

M

Mark Schneider

Hi,

would be nice if anyone could give me a hint on this:

I try to determine to which .xls-File a macro is belonging to (using vba).

In the VBA Editor you can open up the branch for any open file and start a
macro.
BUT: e.g. "activeworkbook" can refer to another workbook.

e.g.
sub test()
msgbox "I am running in workbook " & <anywaytodeterminethat??>
end sub

I need to determine to which branch/parent xls-File the current macro is
belonging,
the Access VBA ways I have in mind (codeproject, module) don't seem to help
here.

Any hints?

TIA
Mark
 
T

Tony Jollans

ThisWorkbook will usually do it, but it can be renamed, in which case I'm
not sure there is any way without having access to the VBA project.
 
M

Mark Schneider

Tony Jollans said:
ThisWorkbook will usually do it, but it can be renamed, in which case I'm
not sure there is any way without having access to the VBA project.
Wow, that did the trick. Never came across the difference between
ActiveWorkbook and ThisWorkbook. Now I can kick out my clumsy workarounds :)
Enjoy, Tony
I enjoy it and thank you very much :)
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top