Word Macro to separate pages into separate documents

This little piece of code takes a word document and saves each page as its own document with the filname “FILENAME_x”. I haven’t done extensive testing, but please feel free to comment.

    Dim i As Integer
    Dim varNumberPages As Variant
    varNumberPages = ActiveDocument.Content.Information(wdActiveEndAdjustedPageNumber)
    For i = 1 To varNumberPages
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1, Name:=""
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.EndKey Unit:=wdStory, Extend:=wdExtend
        ActiveDocument.SaveAs FileName:="FILENAME_" & i & ".doc", FileFormat:= _
            wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
            True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
            False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        Selection.Delete Unit:=wdCharacter, Count:=1
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.HomeKey Unit:=wdStory
    Next i

One thought on “Word Macro to separate pages into separate documents

  1. I just realised something: you need to be careful with where Word saves the files. I have the FileName specified as “FILENAME”, but you should be more specific, i.e. “C:\FILENAME”, otherwise, Word may just use your last location.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s