Log in

View Full Version : Loaded Add-in's path and name in its AutoExec



gandhikumar
02-19-2012, 07:52 PM
Hi all,

I have some trouble in MS Word 2007 VBA's AutoExec subroutine. My problem
is - how to get the location and name of the add-in global template file
when I add it to any word document. The add-in global template has AutoExec subroutine(macro). And I want to know the location in that macro.

I used the code snippet:
VBE.ActiveVBProject.FileName
in AutoExec but it gives some other project name. I suspect that AutoExec runs before its ActiveCodePane is set in VBE.

Please, help me sharpen my VBA knowledge.

Paul_Hossler
02-19-2012, 08:57 PM
not sure if this is what you're looking for


Option Explicit
Sub drv()
Dim oTemplate As Template

For Each oTemplate In Templates

MsgBox oTemplate.Name & " -- " & oTemplate.Path
Next
End Sub


Paul

gandhikumar
02-19-2012, 10:25 PM
Thanks for your reply, Sir.
But, I want to know the name and path of the template in which the AutoExec Macro runs when the template is added to add-ins and not for all other add-ins/templates.

Paul_Hossler
02-20-2012, 05:52 AM
In the Autoexec, wouldn't that just be ThisDocument.Name and ThisDocument.Path?

Paul

gandhikumar
02-20-2012, 06:22 AM
Thank you very much, Sir.
That is the solution I have longed for. Until your last reply, I thought ThisDocument might be similar to ActiveDocument. Now, I am clear. Once again, thank you very much, Sir.

Paul_Hossler
02-20-2012, 11:55 AM
No problem

I'm glad it worked for you

Paul

fumei
02-20-2012, 02:01 PM
1. ThisDocument is similar - but not totally equal to - ActiveDocument.

2. AutoExec? Why are you using AutoExec???

gandhikumar
02-20-2012, 08:53 PM
Dear Mr.fumei,
I have a macro enabled template (.dotm) and it has a set of styles that will be accessed by the macros in it. So, when I load my template to global template/add-ins for an ActiveDocument, the styles of my template must be available to the ActiveDocument before it uses the macros. So that I preferred AutoExec since it executes automatically whenever an add-in/global template is loaded.
But I don't know how to refer the template that have been just loaded until Mr. Paul_Hossler's penultimate reply.
And I thank you for your interest in clearing my doubt.