Launching Word with alternative template skips AutoNew

C

Chad Knudson

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.
 
C

Cindy Meister -WordMVP-

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 :)
 
C

Chad Knudson

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.
 
C

Cindy Meister -WordMVP-

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.

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 :)
 

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