Discussion:
How to run autoexec macro in addins programmatically
(too old to reply)
l***@yahoo.com
2006-03-08 08:40:13 UTC
Permalink
I want to run autoexec macro in addins, and call the Add method of the
AddIns collection. The addins are loaded, and the Installed property is
True. But the autoexec macro in the addins is not run.
Why? How to run autoexec macro in addins programmatically?

I write the code as follows:


Dim gwdApp As Word.Application
Dim strFileName As String

strFileName = Dir(gwdApp.Path & "\STARTUP\")
Do While strFileName <> ""
gwdApp.AddIns.Add gwdApp.Path & "\STARTUP\" & strFileName, True
strFileName = Dir
Loop
'User Profile Addins
strFileName = Dir(gwdApp.StartupPath & "")
Do While strFileName <> ""
gwdApp.AddIns.Add gwdApp.StartupPath & "\" & strFileName, True
strFileName = Dir
Loop



Liu Jianzhong
Cindy M -WordMVP-
2006-03-08 16:46:54 UTC
Permalink
Post by l***@yahoo.com
I want to run autoexec macro in addins, and call the Add method of the
AddIns collection. The addins are loaded, and the Installed property is
True. But the autoexec macro in the addins is not run.
Why? How to run autoexec macro in addins programmatically?
AutoExec macros only execute when Word starts, and the Add-ins are
located in the Startup folder. They do not run when loaded over the
Addins collection. Nor should you store Addins you intend to load as you
show in your code in the Startup folder; they should be in a different
folder.

You can try to use the Application.Run method to run macros in loaded
Addins.
Post by l***@yahoo.com
Dim gwdApp As Word.Application
Dim strFileName As String
strFileName = Dir(gwdApp.Path & "\STARTUP\")
Do While strFileName <> ""
gwdApp.AddIns.Add gwdApp.Path & "\STARTUP\" & strFileName, True
strFileName = Dir
Loop
'User Profile Addins
strFileName = Dir(gwdApp.StartupPath & "")
Do While strFileName <> ""
gwdApp.AddIns.Add gwdApp.StartupPath & "\" & strFileName, True
strFileName = Dir
Loop
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Tony Jollans
2006-03-08 18:39:03 UTC
Permalink
Post by Cindy M -WordMVP-
AutoExec macros only execute when Word starts, and the Add-ins are
located in the Startup folder. They do not run when loaded over the
Addins collection.
I have to disagree with you on that, Cindy. AutoExec macros in global
templates should run when the template is loaded - no matter how, or from
where.

However, automacros do NOT run when Word is started using automation.. If
they are in Word's startup directory, though, they will be loaded so the
code as posted is unnecessary - and, as you say, Application.Run can be used
to explicitly run code.

--
Enjoy,
Tony
Post by Cindy M -WordMVP-
Post by l***@yahoo.com
I want to run autoexec macro in addins, and call the Add method of the
AddIns collection. The addins are loaded, and the Installed property is
True. But the autoexec macro in the addins is not run.
Why? How to run autoexec macro in addins programmatically?
AutoExec macros only execute when Word starts, and the Add-ins are
located in the Startup folder. They do not run when loaded over the
Addins collection. Nor should you store Addins you intend to load as you
show in your code in the Startup folder; they should be in a different
folder.
You can try to use the Application.Run method to run macros in loaded
Addins.
Post by l***@yahoo.com
Dim gwdApp As Word.Application
Dim strFileName As String
strFileName = Dir(gwdApp.Path & "\STARTUP\")
Do While strFileName <> ""
gwdApp.AddIns.Add gwdApp.Path & "\STARTUP\" & strFileName, True
strFileName = Dir
Loop
'User Profile Addins
strFileName = Dir(gwdApp.StartupPath & "")
Do While strFileName <> ""
gwdApp.AddIns.Add gwdApp.StartupPath & "\" & strFileName, True
strFileName = Dir
Loop
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
l***@yahoo.com
2006-03-09 02:43:03 UTC
Permalink
Thanks for your help. But I have a question.

I want to run all AutoExec macro in all addins in the Startup folder. I
must know the name of the AutoExec macro if I use Application.Run. It
can be any combination of template, module, and macro name. How can I
know the name of the AutoExec macro? And what name is it if If the
addin is a .WLL file.
For example, I can write the code as follows. I must know the macro
name.


Dim gwdApp As Word.Application
Dim strFileName As String


strFileName = Dir(gwdApp.Path & "\STARTUP\")
Do While strFileName <> ""
gwdApp.Run "'" & gwdApp.Path & "\STARTUP\" & strFileName &
"'!AutoExec.Main"
strFileName = Dir
Loop
'User Profile Addins
strFileName = Dir(gwdApp.StartupPath & "")
Do While strFileName <> ""
gwdApp.Run "'" & gwdApp.StartupPath & strFileName &
"'!AutoExec.Main"
strFileName = Dir
Loop


Liu Jianzhong
Tony Jollans
2006-03-09 08:33:24 UTC
Permalink
There are reasons that AutoMacros do not run under automation and I do not
think you should just blindly be running them all. You should know what they
are doing and, if you do, you will also know what they are called - of
course it cannot be any combination of anything, automacros are identified
by their names. In a roundabout way it is possible to run them but I really
don't recommend it - do whatever you want to do explicitly.

--
Enjoy,
Tony
Post by l***@yahoo.com
Thanks for your help. But I have a question.
I want to run all AutoExec macro in all addins in the Startup folder. I
must know the name of the AutoExec macro if I use Application.Run. It
can be any combination of template, module, and macro name. How can I
know the name of the AutoExec macro? And what name is it if If the
addin is a .WLL file.
For example, I can write the code as follows. I must know the macro
name.
Dim gwdApp As Word.Application
Dim strFileName As String
strFileName = Dir(gwdApp.Path & "\STARTUP\")
Do While strFileName <> ""
gwdApp.Run "'" & gwdApp.Path & "\STARTUP\" & strFileName &
"'!AutoExec.Main"
strFileName = Dir
Loop
'User Profile Addins
strFileName = Dir(gwdApp.StartupPath & "")
Do While strFileName <> ""
gwdApp.Run "'" & gwdApp.StartupPath & strFileName &
"'!AutoExec.Main"
strFileName = Dir
Loop
Liu Jianzhong
l***@yahoo.com
2006-03-10 02:41:39 UTC
Permalink
Thanks.
But I hope to get the same result as a user operating. When a user open
a document, the .dot or .wll file in the Startup folder will be loaded
automatically, and the AutoExec macro will run automatically. But open
the document by a program, these AutoExec macros can not run
automatically. I hope to get the same result using my program. Is there
any way to do this?

Liu Jianzhong
Charles Kenyon
2006-03-10 05:16:14 UTC
Permalink
Yes, when you load your Add-In programmatically, run the macros you want,
also programmatically.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
Post by l***@yahoo.com
Thanks.
But I hope to get the same result as a user operating. When a user open
a document, the .dot or .wll file in the Startup folder will be loaded
automatically, and the AutoExec macro will run automatically. But open
the document by a program, these AutoExec macros can not run
automatically. I hope to get the same result using my program. Is there
any way to do this?
Liu Jianzhong
l***@yahoo.com
2006-03-10 07:35:55 UTC
Permalink
But I do not know the AutoExec macro name. For example, it may be
"AutoExec.Main" or "ModuleName.AutoExec". I do not know the module
name. I can not run it using Application.Run.


gwdApp.Run "'" & gwdApp.StartupPath & strFileName & "'!AutoExec.Main"
or
gwdApp.Run "'" & gwdApp.StartupPath & strFileName & "'!" &
strModuleName & ".AutoExec"

Liu Jianzhong
Charles Kenyon
2006-03-10 14:25:18 UTC
Permalink
Then it can't be done.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
Post by l***@yahoo.com
But I do not know the AutoExec macro name. For example, it may be
"AutoExec.Main" or "ModuleName.AutoExec". I do not know the module
name. I can not run it using Application.Run.
gwdApp.Run "'" & gwdApp.StartupPath & strFileName & "'!AutoExec.Main"
or
gwdApp.Run "'" & gwdApp.StartupPath & strFileName & "'!" &
strModuleName & ".AutoExec"
Liu Jianzhong
Tony Jollans
2006-03-10 12:43:39 UTC
Permalink
In short, no, you cannot do this. Auto macros are disabled in applications
started via automation.

--
Enjoy,
Tony
Post by l***@yahoo.com
Thanks.
But I hope to get the same result as a user operating. When a user open
a document, the .dot or .wll file in the Startup folder will be loaded
automatically, and the AutoExec macro will run automatically. But open
the document by a program, these AutoExec macros can not run
automatically. I hope to get the same result using my program. Is there
any way to do this?
Liu Jianzhong
l***@yahoo.com
2006-03-09 02:43:33 UTC
Permalink
Thanks for your help. But I have a question.

I want to run all AutoExec macro in all addins in the Startup folder. I
must knoe the name of the AutoExec macro if I use Application.Run. It
can be any combination of template, module, and macro name. How can I
know the name of the AutoExec macro? And what name is it if If the
addin is a .WLL file.
For example, I can write the code as follows. I must know the macro
name.


Dim gwdApp As Word.Application
Dim strFileName As String


strFileName = Dir(gwdApp.Path & "\STARTUP\")
Do While strFileName <> ""
gwdApp.Run "'" & gwdApp.Path & "\STARTUP\" & strFileName &
"'!AutoExec.Main"
strFileName = Dir
Loop
'User Profile Addins
strFileName = Dir(gwdApp.StartupPath & "")
Do While strFileName <> ""
gwdApp.Run "'" & gwdApp.StartupPath & strFileName &
"'!AutoExec.Main"
strFileName = Dir
Loop


Liu Jianzhong
l***@yahoo.com
2006-03-09 02:47:06 UTC
Permalink
Thanks for your help. But I have a question.

I want to run all AutoExec macro in all addins in the Startup folder. I
must know the name of the AutoExec macro if I use Application.Run. It
can be any combination of template, module, and macro name. How can I
know the name of the AutoExec macro? And what name is it if If the
addin is a .WLL file.
For example, I can write the code as follows. I must know the macro
name.


Dim gwdApp As Word.Application
Dim strFileName As String


strFileName = Dir(gwdApp.Path & "\STARTUP\")
Do While strFileName <> ""
gwdApp.Run "'" & gwdApp.Path & "\STARTUP\" & strFileName &
"'!AutoExec.Main"
strFileName = Dir
Loop
'User Profile Addins
strFileName = Dir(gwdApp.StartupPath & "")
Do While strFileName <> ""
gwdApp.Run "'" & gwdApp.StartupPath & strFileName &
"'!AutoExec.Main"
strFileName = Dir
Loop


Liu Jianzhong
Loading...