Suppress VB dialog in Word

C

Charles Parker

I am using COM and WORD automation to open and save a document file to HTML
format. The problem I am having is I have one document that displays a
Microsoft Visual Basic dialog box with the message "Sub or Function not
defined". I need to suppress this dialog from being displayed. I have
suppressed all the other dialogs that have popped up except this one. How do
I suppress this using COM automation. In fact I would like to just get a COM
error but this message or error does not produce a COM error.

The code being used is a s follows:

hr = pWordApp.CreateInstance(__uuidof(Word::Application));
if (SUCCEEDED(hr))
{
vtFileFormat.vt = VT_I4;
vtFileFormat.intVal = wdFormatHTML;

pWordDocs = pWordApp->GetDocuments();
pWordApp->PutDisplayAlerts(Word::wdAlertsNone);// Do not display the
overwrite dialog
pWordDoc = pWordDocs->Open(vtFileName, &vtMissing, &vtReadOnly,
&vtAddToMRU);

pWordDoc->SaveAs(vtFileNameHTML, &vtFileFormat, &vtMissing, &vtMissing,
&vtAddToMRU);
pWordDoc->Close(&vtSaveChanges);
}

This message is display both during Open and Close. Is there a way to
suppress this or all possible dialog boxes? The PutDisplayAlerts method is
not working for this message. Thanks in advance.

Charles...
 
C

Cindy M -WordMVP-

Hi Charles,

Suppressing messages in Word is a bit of a lottery. In this particular case,
it sounds as if there's macro code in the document that's trying to execute
(Document_Open or AutoOpen proc, most likely).

If we're talking Word 2002 or 2003, then you do have the
Application.AutomationSecurity property you can use. Set this to the
equivalent of "High" macro security in the UI, and all macros will be locked
out when you open documents during your code execution. That should keep this
particular message from appearing.
I am using COM and WORD automation to open and save a document file to HTML
format. The problem I am having is I have one document that displays a
Microsoft Visual Basic dialog box with the message "Sub or Function not
defined". I need to suppress this dialog from being displayed. I have
suppressed all the other dialogs that have popped up except this one. How do
I suppress this using COM automation. In fact I would like to just get a COM
error but this message or error does not produce a COM error.

The code being used is a s follows:

hr = pWordApp.CreateInstance(__uuidof(Word::Application));
if (SUCCEEDED(hr))
{
vtFileFormat.vt = VT_I4;
vtFileFormat.intVal = wdFormatHTML;

pWordDocs = pWordApp->GetDocuments();
pWordApp->PutDisplayAlerts(Word::wdAlertsNone);// Do not display the
overwrite dialog
pWordDoc = pWordDocs->Open(vtFileName, &vtMissing, &vtReadOnly,
&vtAddToMRU);

pWordDoc->SaveAs(vtFileNameHTML, &vtFileFormat, &vtMissing, &vtMissing,
&vtAddToMRU);
pWordDoc->Close(&vtSaveChanges);
}

This message is display both during Open and Close. Is there a way to
suppress this or all possible dialog boxes? The PutDisplayAlerts method is
not working for this message.

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

Chad DeMeyer

Also, before creating the document object in your COM code, you may be able
to call:

Application.WordBasic.DisableAutoMacros

That is VBA syntax, not sure what syntax to use in your development
platform.

Regards,
Chad DeMeyer
 

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