none
Problem with Mail Merge in Office 2013 RRS feed

  • Question

  • Hi all,

    We are moving to Office 2013 in our shop, from Office 2007.  We have an Access application that invokes Mail Merge through VBA.  We are running Windows 7 in the desktop environment.

    When running the application in Office 2013, invoking the Mail Merge throws the run-time error 5852, “Requested object is not available”.  I have checked the SQLSecurityCheck for Word in the registry and it is 0.  I have also stepped through the Mail Merge process in the Word document and that works fine.  The data source is an Access query.

    Here is the code:

            wdApp.Documents.Open AppPath & MergeDocumentName

            wdApp.Visible = True

            wdApp.Documents(MergeDocumentName).MailMerge.ViewMailMergeFieldCodes = False

            wdApp.Documents(MergeDocumentName).MailMerge.OpenDataSource Name:=DataSourceName, _

                Connection:="QUERY qryCreateFinalDecree", Format:=wdOpenFormatDocument, SubType:=wdMergeSubTypeWord

            wdApp.ActiveDocument.MailMerge.SuppressBlankLines = True

            wdApp.Documents(MergeDocumentName).MailMerge.Execute

            wdApp.Documents(MergeDocumentName).Close SaveChanges:=wdDoNotSaveChanges

    The code is failing on the third line.

    I would greatly appreciate any information to help solve this problem.

    Thank you,

    Eric Lindberg 

    Monday, July 13, 2015 5:37 PM

Answers

  • Hi Brian,

    I think I have solved the problem by commenting out the reference to ViewMailMergeFieldCodes.  The code still runs OK without it.

    Thanks for responding.

    Eric

    • Marked as answer by L.HlModerator Friday, July 24, 2015 5:31 AM
    Monday, July 20, 2015 7:09 PM

All replies

  • Hi Eric,

    I haven't done a mail merge, but this website said something about if the document is not the active document, the code could produce an error. Do you know if the document has to be activated first?

    Just a thought...

    Monday, July 13, 2015 5:46 PM
  • Hi,

    >>The code is failing on the third line.

    What's your error message for thr third line ? Could you please share more information which could be better for narrowing down the issue ?

    Best Regards,

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 14, 2015 8:30 AM
    Moderator
  • Hi Lan,

    The error message is error 5852, “Requested object is not available”.

    Thanks,

    Eric

     

    Tuesday, July 14, 2015 5:13 PM
  • Hi,

    So have you tried to maybe activate it first? Just curious.

    Wednesday, July 15, 2015 2:05 PM
  • Hi DB guy,

    I believe it is considered the active document when it is opened, as it is the only one so referenced in the WdApp object.  In fact, the third line of code was originally:

    wdApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False

    Thanks,

    Eric

    Wednesday, July 15, 2015 5:20 PM
  • Hi,

    ViewMailMergeFieldCodes  will determine if merge field names are displayed in a mail merge main document .What's the type for the activedocument,  is it a mail merge main document ?

    Best Regards,

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Saturday, July 18, 2015 9:08 AM
    Moderator
  • Hi DB guy,

    I believe it is considered the active document when it is opened, as it is the only one so referenced in the WdApp object.  In fact, the third line of code was originally:

    wdApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False

    Thanks,

    Eric

    Hi Eric,

    As I had said earlier, I don't have any experience with mail merges, but the Help article I linked to earlier specifically "activated" the document, so I just thought it wouldn't hurt for you to try the same approach. But if you're sure that the document is already active, then I am not sure what else to recommend. Good luck!

    Cheers!

    Saturday, July 18, 2015 4:49 PM
  • Hi Eric,

    You need to tell word the main document  is a merge document. Try this 

       Set wdocSource = wdapp.Documents.Open(strFile)
       With wdocSource
          .MailMerge.MainDocumentType = wdFormLetters
          .MailMerge.OpenDataSource Name:= Datasource ...
            ... etc.
    
             ...
       end with
    


    Brian, ProcessIT- Hawke's Bay, New Zealand

    Sunday, July 19, 2015 9:40 PM
  • Hi Lan,

    I believe it is a mail merge main document. I think I have solved the problem by commenting out the reference to ViewMailMergeFieldCodes.  The code still runs OK without it.

    Thanks,

    Eric 

    Monday, July 20, 2015 7:08 PM
  • Hi Brian,

    I think I have solved the problem by commenting out the reference to ViewMailMergeFieldCodes.  The code still runs OK without it.

    Thanks for responding.

    Eric

    • Marked as answer by L.HlModerator Friday, July 24, 2015 5:31 AM
    Monday, July 20, 2015 7:09 PM
  • Hi Eric,

    Nice going. Glad to hear you got it sorted out. Good luck with your project.

    Monday, July 20, 2015 7:42 PM
  • Thanks!
    Monday, July 20, 2015 9:21 PM