• copy of masterdocument including all subdocuments

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » copy of masterdocument including all subdocuments

    Author
    Topic
    #476111

    Hello,
    I am creating some VBA code to strip selected parts of a Word document.
    But the document I am working with is a master document.
    What code do I use to save a copy of the master document with all subdocuments included (so no connections to the subdocuments anymore = no master document)

    Thanks in advance for your reactions.

    Patrick Schouten
    The Netherlands

    Viewing 1 reply thread
    Author
    Replies
    • #1276374

      Hi Patrick,

      Before you go any further, read: http://www.word.mvps.org/FAQs/AppErrors/CorruptDoc.htm and http://word.mvps.org/FAQs/General/WhyMasterDocsCorrupt.htm

      To merge the docments, you could try something along the lines of:

      Code:
      Sub MergeDocs()
      With ActiveDocument.Subdocuments
        If .Count > 0 Then
          .Merge FirstSubdocument:=1, _
          LastSubdocument:=.Count
        End If
      End With
      End Sub

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    • #1276535

      Paul’s code appears to join the separate subdocs into a single one but this version should embed all subdocs

      Code:
      Sub MergeDocs()
        With ActiveDocument.Subdocuments
          While .Count > 0
            .Item(1).Delete
          Wend
        End With
      End Sub
      • #1276731

        Paul and Andrew,
        Thank you both for your quick respones.
        This code will get me further.

        Greetings,
        Patrick Schouten
        The Netherlands

    Viewing 1 reply thread
    Reply To: copy of masterdocument including all subdocuments

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: