Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Launching Word with alternative template skips AutoNew

2 views
Skip to first unread message

Chad Knudson

unread,
Sep 8, 2003, 2:44:50 AM9/8/03
to
I am launching Word from an ActiveX control I've written and attempting to
use an alternative template that contains an AutoNew macro. When I launch
word, the new document is created based on the alternative template, and I
get the warning about macro security, but the AutoNew sub is never run. I
need to have the AutoNew sub run or find an appropriate equivalent so that
my macro is started up right away without user intervention.


Cindy Meister -WordMVP-

unread,
Sep 8, 2003, 4:34:46 AM9/8/03
to
Hi Chad,

> I am launching Word from an ActiveX control I've written and attempting to
> use an alternative template that contains an AutoNew macro. When I launch
> word, the new document is created based on the alternative template, and I
> get the warning about macro security, but the AutoNew sub is never run.
>

HOW is your activex control "launching" this? Show us the code, please.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

Chad Knudson

unread,
Sep 8, 2003, 11:17:08 AM9/8/03
to
STARTUPINFO si;
PROCESS_INFORMATION pi;
char szCommandLine[1024];
char szParameters[1024];

wsprintf(szParameters, "/q /t\"%s\"", szTemplateFileName);
wsprintf(szCommandLine, "%s %s", szWordExe, szParameters); // szWordExe
contains the full path and filename of the WINWORD.EXE executable
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

CreateProcess(NULL, // No module name (use command line).
szCommandLine, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi); // Pointer to PROCESS_INFORMATION structure.

I've also used ShellExecuteEx and achieved the same result -- Word is
launched with a new document based on the supplied template but the AutoNew
macro is not executed.

"Cindy Meister -WordMVP-" <CindyM...@swissonline.ch> wrote in message
news:VA.00008461.00657eaa@speedy...

Cindy Meister -WordMVP-

unread,
Sep 9, 2003, 6:09:08 AM9/9/03
to
Hi Chad,

> I've also used ShellExecuteEx and achieved the same result -- Word is
> launched with a new document based on the supplied template but the AutoNew
> macro is not executed.
>

Yes, what you're encountering is "known and expected" behavior. AutoNew does
not launch when the /t switch is used. That's how it's been since the switch
was introduced, and although it wasn't a factor at the time, given the virus
problems, it's turned out to be a very good thing...

You can launch Word using Shell (or whatever commandline method you wish)
with no problem. But you'll need to actually automate Word (GetObject, or
CreateObject) and use the .Add method to have the template open and execute
the AutoNew macro.

0 new messages