Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Feb 2004
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does anybody know how to change pages into documents via a macro or something? I have 96 lines in a document I need to have separated out into 96 documents.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Here is a macro from Experts Exchange (unfortunately it's not possible to post a link to solutions on that website):

    [codebox] Public Sub SplitWordDoc()
    Dim sPath As String
    Dim sName As String
    Dim p As Long
    Dim docNew As Document
    Dim rngSource As Range

    'gets document application path to provide saving location
    sPath = ActiveDocument.Path & "\"
    sName = Replace(ActiveDocument.Name, ".doc", "", Compare:=vbTextCompare)

    'go to start of document
    Selection.HomeKey wdStory

    Application.ScreenUpdating = False

    'get current page count
    ActiveDocument.Repaginate

    'for each page in the document
    For p = 1 To ActiveDocument.BuiltInDocumentProperties(wdPropert yPages)
    'select the page
    ActiveDocument.Bookmarks("\Page").Range.Select
    'move left 1 character
    Selection.MoveLeft wdCharacter, 1, wdExtend
    'set the range to be copied to new document
    Set rngSource = Selection.Range.FormattedText

    'create new document
    Set docNew = Documents.Add
    'copy page contents
    docNew.Range.FormattedText = rngSource
    'save the document
    docNew.SaveAs sPath & sName & "_Page" & p & ".doc"
    'close the document
    docNew.Close True

    'go to the next page
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext
    Next p

    'go to start of document
    Selection.HomeKey wdStory

    Application.ScreenUpdating = True
    End Sub[/codebox]

  3. #3
    Lounger
    Join Date
    Feb 2004
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans,

    You are an absolute star. Many thanks! You made my day!


    [quote name='HansV' post='782575' date='01-Jul-2009 12:29']Here is a macro from Experts Exchange (unfortunately it's not possible to post a link to solutions on that website):

    [codebox] Public Sub SplitWordDoc()
    Dim sPath As String
    Dim sName As String
    Dim p As Long
    Dim docNew As Document
    Dim rngSource As Range

    'gets document application path to provide saving location
    sPath = ActiveDocument.Path & "\"
    sName = Replace(ActiveDocument.Name, ".doc", "", Compare:=vbTextCompare)

    'go to start of document
    Selection.HomeKey wdStory

    Application.ScreenUpdating = False

    'get current page count
    ActiveDocument.Repaginate

    'for each page in the document
    For p = 1 To ActiveDocument.BuiltInDocumentProperties(wdPropert yPages)
    'select the page
    ActiveDocument.Bookmarks("\Page").Range.Select
    'move left 1 character
    Selection.MoveLeft wdCharacter, 1, wdExtend
    'set the range to be copied to new document
    Set rngSource = Selection.Range.FormattedText

    'create new document
    Set docNew = Documents.Add
    'copy page contents
    docNew.Range.FormattedText = rngSource
    'save the document
    docNew.SaveAs sPath & sName & "_Page" & p & ".doc"
    'close the document
    docNew.Close True

    'go to the next page
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext
    Next p

    'go to start of document
    Selection.HomeKey wdStory

    Application.ScreenUpdating = True
    End Sub[/codebox][/quote]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •