Word Mail Merge Run-time error '450' Wrong number of arguments

  • 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:

    Again, the error is on the following line:

    Code
    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!

  • Re: Word Mail Merge Run-time error '450' Wrong number of arguments


    I've not tried to create mail merges strickly via VBA - I've always had a template made up as the source document.


    But, I'm guessing those are you field names <<_FIRSTO>>, etc.? If so, shouldn't they all be surrounded by <<>>? There are a number that have the opening but not the closing (or there is a CR/LF in the middle) and some that have spaces in there which I don't think leading spaces are allowed in field names. It also appears you are trying to put included text into the middle (the "," for state) but that is inside of the <<>> as well which would be interpreted as a field name.



    Are you running this macro from Word or Excel? Doesn't make a difference, just trying to figure if there is something else to look at.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!