Hey experts!
I am trying to do a Mail Merge from excel, open up a word document, prompt the user for the type of paper they are using, then preform the mail merge and print out address blocks. I have everything working up to the point where I try to add the address block. I get an error on that line stating:
"Run-time error '450'
Wrong number of arguments or invalid property assignment."
My code is as follows:
Sub davidMailMerge()
Dim appWD As Object
Dim mmDoc As Object
Set appWD = CreateObject("Word.Application") 'creates new word app
appWD.Visible = True 'set visible
Set mmDoc = appWD.Documents.Add 'add document and call it mmDoc
mmDoc.mailMerge.MainDocumentType = wdMailingLabels 'set mmDoc to type MailMerge Lables
mmDoc.mailMerge.Application.Dialogs(1367).Show 'shows dialog to choose paper type
With appWD.ActiveDocument.mailMerge
.OpenDataSource Name:= _
"C:\Users\David\Desktop\fsguest.xlsm", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\David\Desktop\fsguest.xlsm;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:D" _
, SQLStatement:="SELECT * FROM [People Database$]", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
wdFieldAddressBlock, Text:= _
"\f ""<<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>" & Chr(13) & "<<_COMPANY_" & Chr(13) & ">><<_STREET1_" & Chr(13) & ">><<_STREET2_" & Chr(13) & ">><<_CITY_>><<, _STATE_>><< _POSTAL_>><<" & Chr(13) & "_COUNTRY_>>"" \l 1033 \c 2 \e ""United States"
.Destination = wdSendToNewDocument
.Execute
End With
End Sub
Display More
Again, the error is on the following line:
ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
wdFieldAddressBlock, Text:= _
"\f ""<<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>" & Chr(13) & "<<_COMPANY_" & Chr(13) & ">><<_STREET1_" & Chr(13) & ">><<_STREET2_" & Chr(13) & ">><<_CITY_>><<, _STATE_>><< _POSTAL_>><<" & Chr(13) & "_COUNTRY_>>"" \l 1033 \c 2 \e ""United States"
That line of code that errors was directly taken from a Word generated Macro. I have tried leaving off the ActiveDocument part because I am inside the With statement, but that didn't seem to change anything.
I am running in a Windows 7 environment and using Office 2010.
Please let me know of any ideas, or if you need more information. The merge with the excel document works as expected doing a manual merge.
Thanks!