PDA

View Full Version : [SOLVED:] Bypassing "SQL Command" dialog box in a macro to automate a mail merge



ShogunPatch
03-19-2018, 09:10 AM
I have prepared a macro which opens a mail merge document and then runs the mail merge; however, each time I run it I get a dialog box saying "Opening this document will run the following SQL command... blah blah... Do you want to continue" and I have to select "Yes" for the macro to continue running successfully.
Is there a way to avoid the user having to click on "Yes" for the macro to run? I have tried experimenting with switching Application.DisplayAlerts on and off and also with SendKeys, so far without success. Ideally, I don't want to switch off all dialogs, I just want the macro to run smoothly without interruption from that particular box.
Here is my code:


Sub CreateExpertiseFromBlank()
'
' CreateExpertise Macro
' Uses mail merge template to create a formatted expertise list from an Excel source table into a blank doc
'
Documents.Open ("C:\Users\ShogunPatch\Dropbox\MyDesktop\ExpertiseList.docm")
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Selection.WholeStory
Selection.Fields.Update
' Application.DisplayAlerts = True
End Sub


Any help would, as ever, be much appreciated.

macropod
03-23-2018, 04:22 PM
Is there a way to avoid the user having to click on "Yes" for the macro to run? I have tried experimenting with switching Application.DisplayAlerts on and off and also with SendKeys, so far without success
Setting:

Application.DisplayAlerts = wdAlertsNone
before you open the mailmerge main document will suppress the SQL prompt, but it will also kill the mailmerge - in which case you macro becomes responsible for re-establishing all the mailmerge parameters (mailmerge type, datasource, and so on).

Alternatively, there is a registry edit, but that is user-specific and affects all mailmerge main documents opened by that user.

ShogunPatch
03-26-2018, 01:57 AM
That sounds like it might do exactly what I need... I shall investigate and revert back. Thanks!