View Single Post
  #4   Report Post  
Posted to microsoft.public.word.docmanagement
UlfHJensen UlfHJensen is offline
external usenet poster
 
Posts: 8
Default One field referencing multiple bookmarks

Thanks Graham,
Your first paragraph assumptions are indeed correct and hence the macro
would probably work. I'll give it a try.
--
Best regards
Ulf


"Graham Mayor" wrote:

One possibility, assuming that you will use only single letters and that
each new letter is incremented by alphabet, you could add a docvariable
field to the header
{DocVariable varLetter} and run the following macro. This will update the
field to display the highest bookmark letter. It works on the premise that
bookmarks are filed alphabetically so when the macro checks each single
digit bookmark, the highest letter is recorded in the document variable.

Dim oVars As Variables
Dim oBM As Bookmark
Dim oStory As Range
Set oVars = ActiveDocument.Variables
For Each oBM In ActiveDocument.Bookmarks
If Len(oBM.name) = 1 Then
oVars("varLetter").Value = oBM.name
End If
Next oBM
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing

If you want all the Bookmark letters present in the document to be listed
then you would need the following variation

Dim oVars As Variables
Dim oBM As Bookmark
Dim sList As String
Dim oStory As Range
sList = ""
Set oVars = ActiveDocument.Variables
For Each oBM In ActiveDocument.Bookmarks
If Len(oBM.name) = 1 Then
sList = sList & oBM.name & _
Chr(44) & Chr(32)
End If
Next oBM
sList = Left(sList, Len(sList) - 2)
sList = Left(sList, Len(sList) - 3) & Chr(32) _
& Chr(38) & Chr(32) & Right(sList, 1)
oVars("varLetter").Value = sList
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing

http://www.gmayor.com/installing_macro.htm
--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



"UlfHJensen" wrote in message
...
I have a document containing several bookmarks, each a new letter for
revision; A, B, C...G. For each new version of the document, a new field
and
letter is entered by the responsible. This procedure is ok (for now) and
works fine.
In the header of my document I would like the latest revision letter to
appear in a field.
How do I program my way out of:

Check if bookmarks until last filled is found
Clear field in header
Insert latest (last filled bookmark) revision

Any suggestions appreciated.
--
Best regards
Ulf



.