S
Saf
I found the original code through this link:
http://support.microsoft.com/?kbid=216201
It is meant to split a document at the section breaks and save each section
as its own brand new word document. I'm running Word2003 and the code works
wonderfully well.
I attempted to change the file name provided within the vba code. My doc is
from a mail merge and I want it to pull the text from paragraph 8 as part of
the new file names (ActiveDocument.SaveAs FileName:="Mail09_" & para & ".doc")
I'm very new to this and I get the following error when I compile: "Run-time
error '5487' Word cannot complete the save due to a file permission error."
Can someone please help me fix the code? I'm not even sure what the error
means. Also, is it possible to pull only a portion of the paragraph, i.e.
only the last word?? If not, or if its too cumbersome, thats ok.
Sub BreakOnSection()
'Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection
'A mailmerge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
'Select and copy the section text to the clipboard
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
'Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "S:\"
'Changed this portion of the code to use paragraph # 8 from the section
para = ActiveDocument.Paragraphs(8)
ActiveDocument.SaveAs FileName:="Mail09_" & para & ".doc"
ActiveDocument.Close
'Move the selection to the next section in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
Thank you in advance for any help!
Saf
http://support.microsoft.com/?kbid=216201
It is meant to split a document at the section breaks and save each section
as its own brand new word document. I'm running Word2003 and the code works
wonderfully well.
I attempted to change the file name provided within the vba code. My doc is
from a mail merge and I want it to pull the text from paragraph 8 as part of
the new file names (ActiveDocument.SaveAs FileName:="Mail09_" & para & ".doc")
I'm very new to this and I get the following error when I compile: "Run-time
error '5487' Word cannot complete the save due to a file permission error."
Can someone please help me fix the code? I'm not even sure what the error
means. Also, is it possible to pull only a portion of the paragraph, i.e.
only the last word?? If not, or if its too cumbersome, thats ok.
Sub BreakOnSection()
'Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection
'A mailmerge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
'Select and copy the section text to the clipboard
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
'Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "S:\"
'Changed this portion of the code to use paragraph # 8 from the section
para = ActiveDocument.Paragraphs(8)
ActiveDocument.SaveAs FileName:="Mail09_" & para & ".doc"
ActiveDocument.Close
'Move the selection to the next section in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
Thank you in advance for any help!
Saf