Word Macro Trouble - Please Help Newbie!

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
 
F

fulotta

Run-time error 5941 - The requested member of the collection does not
exist......I'm not sure how to proceed at this point?!
 
C

Charles Kenyon

Post what it is you are trying to accomplish, together with your code, in
the word.vba.beginner newsgroup?
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top