Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

BaseName help - Can't access/grab text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fulotta - 15 Sep 2005 05:01 GMT
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
Helmut Weber - 15 Sep 2005 12:15 GMT
Hi,

bookmarks are unique to a document.
If you create a mailmerge document from a document,
which contains bookmarks, the bookmarks are gone
in the merged document, IMHO.

ActiveDocument.Bookmarks.Field("story")
won't work anyway.

There are no fields in the bookmarks' collection, only Bookmarks.

And I wonder, whether "story" could be a field's index.

There may be fields in a certain bookmark's range, like

msgbox activedocument.bookmarks("Mark1").range.fields(1).result

No use anyway, as there are no bookmarks in the merged doc.

And for bulding the files' fullnames:

Example:

Sub Test0023()
Dim l As Long
Dim sFln As String ' filename
Dim sPth As String ' path
sPth = "c:\test\"
For l = 1 To 10
  sFln = sPth & ActiveDocument.Fields(1).Result
  ActiveDocument.Fields(1).Delete
  sFln = sFln & Format(l, "000") & ".doc"
  MsgBox sFln
Next
End Sub

HTH

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.