I've been trying to "bypass" the Select From Sheet1$
alert that appears when you MailMerge a Word doc with an Excel doc.
I tried to save each document "without the data source attached, but modify the VBA code in each document to do the appropriate OpenDataSource" as stated in excel VBA to Automatically select Yes when prompted during mail merge
But still Word asks for the Selection of Sheet1$
.
Besides, the DisplayAlerts=0
is not working for me. I'm guessing that just as @Ashton Sheets, "I'm having an issue with placement. When I have wdDoc.DisplayAlerts = 0
set BEFORE I set wdDoc = GetObject(wdInputName, "Word.document")
it obviously doesn't work because wdDoc
isn't set. But if I put it immediately following the line it is too late because the word is only THEN opening and that's exactly when the message appears - so it's "too late" as stated in
How to use VBA to say 'Yes' to any SQL prompts in word?
The idea of this code is to avoid any possible errors from users. Therefore the least amount of "clicks" from the operator is a must. Including MsgBox
s...
It's also important to mention that I am using Office 2007 to program this. And the HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options
is not an option due to the several users and computers that will be employing the code.
Here is an example of the Code:
Option Explicit
Sub wrd()
Dim name As String
Dim wrdapp As Word.Application
Dim wrddoc As Word.Document
Set wrdapp = CreateObject("word.application")
wrdapp.Visible = True
'wrdapp.DisplayAlerts = False
Word.Application.DisplayAlerts = False
Set wrddoc = wrdapp.Documents.Open("C:\............\3.2_CTO. A.FIN..docx")
With wrddoc
'.Application.DisplayAlerts = wdAlertsNone
.MailMerge.OpenDataSource ("C:\.......\3.1_Base de datos_FIN.xlsx")
.MailMerge.HighlightMergeFields = True
.MailMerge.ViewMailMergeFieldCodes = False
.MailMerge.DataSource.ActiveRecord = wdLastDataSourceRecord
name = Hoja14.Range("a2")
.SaveAs ("C:\...........\Clientes\Persona Física\Cto. " & (tipo) & "# " & (name) + ".docx")
wrdapp.Quit
Set wrddoc = Nothing
Set wrdapp = Nothing
Application.DisplayAlerts = True
End With
End Sub