none
VBA Word - Did anyone ever figure out why Doug Robbins' "splitter Macro" creates an extra page per document? RRS feed

Answers

  • >> I still don't know why it's adding an extra page via a section break

    Not sure whether this will answer your question either, but when Word does a "Letter" merge to a New Document (not a "Directory" merge), it inserts a section break (not a page break) after each "letter" is merged. So whatever code you use to split the resulting document up has to deal with those section breaks, one way or another. If you don't remove the break, you'll get an extra page.

    I doubt this is relevant to your problem , but in the *general* case, a splitter can't rely on splitting either using pages or using sections, because a mail merge main document that contains a page break or section break means that the resulting "letters" will contain those break types. This isn't actually an easy problem to deal with, which is probably why no-one has come up with a "this deals with all possible scenarios" solution.



    Peter Jamieson

    Thursday, March 26, 2020 7:34 PM

All replies

  • A quick look suggests that it is not "Cutting" the Next Page Section break that Word inserts after each page (except maybe the last) during the merge. 

    I think the following quick fix may solve that, but it isn't good code and I haven't tested much.

    I see macropod posted a reply in the same conversation as Doug, with a link to his own splitter which I imagine will do the right thing and cope with more situations: http://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html


    Peter Jamieson

    Monday, March 23, 2020 7:59 PM
  • Thanks for the suggestion.

    I still don't know why it's adding an extra page via a section break, but I found some code that lets me delete the section break and extra page

    Sub DeleteAllSectionsInOneDoc()
    
    ' credit goes to https://www.datanumen.com/blogs/3-ways-quickly-delete-section-breaks-word-document/ for this code
    
      With Selection
        .HomeKey Unit:=wdStory
        With Selection.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Text = "^b"
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
      End With
      
    End Sub

    Thursday, March 26, 2020 5:55 PM
  • >> I still don't know why it's adding an extra page via a section break

    Not sure whether this will answer your question either, but when Word does a "Letter" merge to a New Document (not a "Directory" merge), it inserts a section break (not a page break) after each "letter" is merged. So whatever code you use to split the resulting document up has to deal with those section breaks, one way or another. If you don't remove the break, you'll get an extra page.

    I doubt this is relevant to your problem , but in the *general* case, a splitter can't rely on splitting either using pages or using sections, because a mail merge main document that contains a page break or section break means that the resulting "letters" will contain those break types. This isn't actually an easy problem to deal with, which is probably why no-one has come up with a "this deals with all possible scenarios" solution.



    Peter Jamieson

    Thursday, March 26, 2020 7:34 PM
  • Yeah, I think this answers the question.  Thanks for sharing your knowledge.

    Using the splitter macro and the DeleteAllSectionsInOneDoc() macro I've accomplished my goal of splitting a document into separate usable pages.

    Thanks again and stay healthy in these trying times.

    Christian


    Friday, March 27, 2020 12:50 PM