none
How do I open an existing document in VB and change the MainDocumentType to wdCatalog? RRS feed

  • Question

  • I have a VB application that automates mail merges and it works fine as long as they are form letter merges.  But if I try to change the MainDocumentType to wdCatalog:

    doc.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdCatalog

    Then the merge doesn't happen...no error.  If I run the debugger, I can see that after the above statement is executed, the value of the property is displayed in red...but no hint what it is objecting to. 

    The examples I find, all show creating a new document, and I am using an existing document...is there something I need to do differently with an existing document?

    Friday, January 27, 2017 4:57 PM

All replies

  • Hi wpenfold,

    Try the code below.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim oWord As word.Application
            Dim oDoc As word.Document
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Open("C:\Users\v-padee\Desktop\demo1.docx")
            oDoc.MailMerge.MainDocumentType = word.WdMailMergeMainDocType.wdCatalog
            oDoc.Save()
            MsgBox(oDoc.MailMerge.MainDocumentType.ToString())
            oDoc.Close()
        End Sub

    Reference:

    MainDocumentType Property

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 30, 2017 1:24 AM
    Moderator