F
fulotta
I'm trying to take a merged document, have the VB macro chop each range
as a separate file and save it as a filename specified by the first
field. For instance, if the first line of text (field is called
"story") in the merged range appears as "car", I would want the file
saved as C:\car001.doc
However, I'm having trouble with the BaseName creation to actually grab
that text from the first line in the document. Please help!?!
Sub Splitter()
Selection.EndKey Unit:=wdStory
numlets = Selection.Information(wdActiveEndSectionNumber)
If numlets > 1 Then numlets = numlets - 1
Selection.HomeKey Unit:=wdStory
For Counter = 1 To numlets
BaseName = "c:\" + ActiveDocument.Bookmarks.Field("story")
DocName = BaseName & Right$("000" & LTrim$(Str$(Counter)), 3)
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:=DocName
ActiveWindow.Close
Next Counter
End Sub
as a separate file and save it as a filename specified by the first
field. For instance, if the first line of text (field is called
"story") in the merged range appears as "car", I would want the file
saved as C:\car001.doc
However, I'm having trouble with the BaseName creation to actually grab
that text from the first line in the document. Please help!?!
Sub Splitter()
Selection.EndKey Unit:=wdStory
numlets = Selection.Information(wdActiveEndSectionNumber)
If numlets > 1 Then numlets = numlets - 1
Selection.HomeKey Unit:=wdStory
For Counter = 1 To numlets
BaseName = "c:\" + ActiveDocument.Bookmarks.Field("story")
DocName = BaseName & Right$("000" & LTrim$(Str$(Counter)), 3)
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:=DocName
ActiveWindow.Close
Next Counter
End Sub