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