Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2007
    Posts
    123
    Thanks
    13
    Thanked 1 Time in 1 Post

    Macro to cut one Word doc into many small ones (Word 2002 SP3)

    Hi everyone. I was wondering if someone might be able to help me code a macro to do the following.

    Let's say I have a Word document, called "My notes", which is full of notes. Each individual note ends with delimiter. (In the attached example I've used "///").

    Let's say there are 30 notes in the My notes.doc. I need a macro which will copy each note into its own new doc, and give the new doc a name (eg. "My notes snipped 0001.doc", "My notes snipped 0002.doc" etc.) save it, and close it.

    Ideally there should be no limit to how many notes are in My notes.doc, although if limitlessness makes this harder to code, 2,000 should be plenty.

    Also ideally, I should be able to easily change
    -- what I want the delimiter to be, and
    -- what the non-unique part of the cut-up file name (in the example above, change from "My notes snipped 0001.doc" to "Cool stuff 0001.doc").

    Is this asking too much from forum readers, or is it more appropriate that I try my luck with some of the for-hire "experts" on Kasamba?

    I'd be grateful for any help.

    PS I am cross-posting this in the VBA section of the forum
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Macro to cut one Word doc into many small ones (Word 2002 SP3)

    This doesn't look too difficult, I'm sure we'll be able to help you with your coding.

    How good are your VBA skills?
    Have you made a start on the code yet?

    regards,

    StuartR

  3. #3
    2 Star Lounger
    Join Date
    Jan 2007
    Posts
    123
    Thanks
    13
    Thanked 1 Time in 1 Post

    Re: Macro to cut one Word doc into many small ones (Word 2002 SP3)

    Thanks Stuart. But no need -- meanwhile some code has since been suggsted to me, and it works very well. For the benefit of anyone who is interested, it is presented below. In this example, the text delimiter is "///" and the root (unnumbered) name of the of the resulting new files is "Notes", so the resuting files will be called "Notes 001.doc.", "Notes 002.doc" etc.

    Sub SplitNotes(delim As String, strFilename As String)
    Dim doc As Document
    Dim arrNotes
    Dim I As Long
    Dim X As Long

    arrNotes = Split(ActiveDocument.Range, delim)

    For I = LBound(arrNotes) To UBound(arrNotes)
    If Trim(arrNotes(I)) <> "" Then
    X = X + 1
    Set doc = Documents.Add
    doc.Range = arrNotes(I)
    doc.SaveAs ThisDocument.Path & "" & strFilename & Format(X, "000")
    doc.Close True
    End If
    Next I

    End Sub

    Sub test()
    SplitNotes "///", "Notes "
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Macro to cut one Word doc into many small ones (Word 2002 SP3)

    That will certainly put the text into a separate document, it will lose any formatting but this may be sufficient for your purposes.

    Thanks for sharing.

    StuartR

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro to cut one Word doc into many small ones

    We had a thread last year on saving each page or section of a document as a new document. If you find that macro, you probably could adapt it to any delimiter you like.

Posting Permissions

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