Respond to message box

P

P Ratcliff

Hi,

I need to have a vba script respond automatically to a message box.
The script is copying a section of a large document, saving it as
another document and then converting that document to html. The
message box I get is: "Recording Clipboard style sheet will require
copying many styles. Do you want to use Normal style instead?" I need
the script to respond with "no". The default is "yes".

The only help I can find is a way to hide the message box which
doesn't help me as that uses the default response.

Thanks in advance,
P Ratcliff
 
P

Pesach Shelnitz

Hi,

This is done by declaring a String variable, using this variable to retrieve
the return value of the MsgBox call, and setting the Buttons parameter to the
appropriate value for the buttons that you want to appear.

For example, in your case, the code would be something like the following.

Dim reply As String

reply = MsgBox("Do you want to use Normal style ?", vbYesNo)
If reply = vbNo Then
' Code to handle the No response.
Else
' Code to handle the default response.
End If
 
K

Karl E. Peterson

I think "R" wants code to handle a message box popped by Word itself, not his/her
own code.
 
D

Doug Robbins - Word MVP

You may be able select No by using SendKeys.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
Top