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


Hi Graham,
I have now tried but -even though the code executes flawlessly - nothing
shows in varLetter. I tried to single step the code and it appears the
statement If Len(oBM... never goes True depsite letters A and B in the
bookmarks respektively, i.e. varLetter show display a "B".
I have treid to troubleshoot myself but I am not that into VBA -yet. I am
not sure what the second part (the oStory-part) actually is intended to do.

Giving my basic idea a re-evaluation, I think probably the easiest way is
(for me, that is) to address directly the bookmarks and assigning (Set?) the
varLetter value from these. I have only 7 allowable revision letters so
having 7 Ifs or similar would not be to confusing. Of course I would have to
clear the contents of varLetter prior to checking for new revision.

Any help on this?

--
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



.