Automate Responding to Prompt in Word 2003
I'm writing a simple macro that opens a Word 2003 document which is a label merge doc.
1.When the document opens, Word prompts to say that Data from my Database will be placed in the document and do I want to continue. At this point I want to write into the macro to automatically respond "Yes". This is the option that is selected by default.
2. Word then prompts to select the text separator from Tab, Comma or Other. Comma is the default selection, and it is the one I want. At this point I want to write into the macro to automatically respond "OK", which is the default selection.
Everything else - the opening as read only, toggling the view, and saving as a new file I have been able to successfully manage.
:afrog:
Re: Automate Responding to Prompt in Word 2003
Welcome to the Forums.
You can temporarily turn off the DisplayAlerts which will force Word to accept the defaults on these
messages. Since your selections will be thedefaults you will be good to go.
In the Document_Open procedure place this code there.
VB Code:
Private Sub Document_Open()
Dim iDA As Integer
iDA = Application.DisplayAlerts
Application.DisplayAlerts = wdAlertsNone
'Do your stuff
'...
'...
'...
Application.DisplayAlerts = iDA
End Sub
Or if you are sutomating Word from VB it will basically be the same.
Re: Automate Responding to Prompt in Word 2003
It looks like when I disable the alerts they get answered in the negative because then the merge commands are disabled. How do I answer the prompts/alerts in the positive? Do I have to find a way to tell the macro which prompt/alert is being displayed or what variables are being used in order to answer it? If so, I'm assuming since these are standard Word alerts there should be standard naming conventions for them. Where would I find this out?
Re: Automate Responding to Prompt in Word 2003
Doesnt it state in the first messagebox that a select statement is going to be run? The default is No.
So this is why its not running.
Re: Automate Responding to Prompt in Word 2003
When I throw in the code to turn off the alerts I do not get anything about a select statement going to be run. What I do get is: Run-Time error '5852' Requested object is not available in regard to:
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
I included that line because I don't want the user to see the merge codes or have anything to do but look at the data.
I see what you're saying about the first prompt with the alerts on being about running the SQL command, but I need that to say yes. So I guess turning off the alerts won't work. So can you point me in the right direction for answering alerts?