Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
UlfHJensen UlfHJensen is offline
external usenet poster
 
Posts: 8
Default One field referencing multiple bookmarks

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
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default One field referencing multiple bookmarks

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



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default One field referencing multiple bookmarks

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



  #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



.

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



.



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



.

  #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



.

  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default One field referencing multiple bookmarks

The macro checks the names of the bookmarks and not the values they contain.
The macro is simply looking for bookmarks called A, B, C etc which it loads
in turn into the variable each overwriting the previous letter, and as they
are in alphabetical order, the last letter is the one that the variable
retains ... until you add another bookmark and re-run the macro.
If you want to send me a sample of your document (use the link on the home
page of my web site - and remove any sensitive data) I would be able to see
exactly what you are doing and maybe suggest a workaround to achieve what
you want. At the moment I am not 100% clear on how you are using the version
information - the bookmark(s) and the 'field'. It may, for example not be
necessary top use a bookmark at all - you could simply write the letter to a
docvariable with a macro and reproduce it with a docvariable field
or
If there is only one letter in the document at a time, format that letter
with a unique character style (that can be the same as the underlying style
except for the name) and reproduce the content of the style - the letter -
in the header using a Styleref field.

If you merely want to reflect the revision letters in the variable then the
following macro will do that - up to a maximum of 7 letters A- G. Run this
macro in the the last saved version of the document. When you save it
increments the letter and saves the document with the same filename in the
same folder with the addition of the incremented letter e.g.

C:\Path\filename revision A.doc

Sub FileSave()
Dim oDoc As Document
Dim oVars As Variables
Dim oStory As Range
Dim sFname As String
Set oDoc = ActiveDocument
Set oVars = oDoc.Variables
On Error Resume Next
If oVars("varLetter").Value = "" Then
oVars("varLetter").Value = " "
End If
If Len(oDoc.Path) = 0 Then
oDoc.Save
End If
sFname = Left(oDoc.FullName, Len(oDoc.FullName) - _
(Len(oDoc.FullName) - InStrRev(oDoc.FullName, ".") + 1))
Select Case oVars("varLetter").Value
Case " ": oVars("varLetter").Value = "A"
Case "A"
oVars("varLetter").Value = "B"
sFname = Replace(sFname, " Revision A", "")
Case "B"
oVars("varLetter").Value = "C"
sFname = Replace(sFname, " Revision B", "")
Case "C"
oVars("varLetter").Value = "D"
sFname = Replace(sFname, " Revision C", "")
Case "D"
oVars("varLetter").Value = "E"
sFname = Replace(sFname, " Revision D", "")
Case "E"
oVars("varLetter").Value = "F"
sFname = Replace(sFname, " Revision E", "")
Case "F"
oVars("varLetter").Value = "G"
sFname = Replace(sFname, " Revision F", "")
Case Else: MsgBox "Maximum permitted revision already added." & vbCr & _
"Revision letter will not be updated" & vbCr & _
"Document will not be saved", vbInformation, "Revisions"
Exit Sub
End Select
For Each oStory In oDoc.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
oDoc.SaveAs sFname & " Revision " & oVars("varLetter").Value
End Sub


--

Graham Mayor - Word MVP

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





"UlfHJensen" wrote in message
...
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



.



  #9   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default One field referencing multiple bookmarks


The macro checks the names of the bookmarks and not the values they contain.
The macro is simply looking for bookmarks called A, B, C etc which it loads
in turn into the variable each overwriting the previous letter, and as they
are in alphabetical order, the last letter is the one that the variable
retains ... until you add another bookmark and re-run the macro.
If you want to send me a sample of your document (use the link on the home
page of my web site - and remove any sensitive data) I would be able to see
exactly what you are doing and maybe suggest a workaround to achieve what
you want. At the moment I am not 100% clear on how you are using the version
information - the bookmark(s) and the 'field'. It may, for example not be
necessary top use a bookmark at all - you could simply write the letter to a
docvariable with a macro and reproduce it with a docvariable field
or
If there is only one letter in the document at a time, format that letter
with a unique character style (that can be the same as the underlying style
except for the name) and reproduce the content of the style - the letter -
in the header using a Styleref field.

If you merely want to reflect the revision letters in the variable then the
following macro will do that - up to a maximum of 7 letters A- G. Run this
macro in the the last saved version of the document. When you save it
increments the letter and saves the document with the same filename in the
same folder with the addition of the incremented letter e.g.

C:\Path\filename revision A.doc

Sub FileSave()
Dim oDoc As Document
Dim oVars As Variables
Dim oStory As Range
Dim sFname As String
Set oDoc = ActiveDocument
Set oVars = oDoc.Variables
On Error Resume Next
If oVars("varLetter").Value = "" Then
oVars("varLetter").Value = " "
End If
If Len(oDoc.Path) = 0 Then
oDoc.Save
End If
sFname = Left(oDoc.FullName, Len(oDoc.FullName) - _
(Len(oDoc.FullName) - InStrRev(oDoc.FullName, ".") + 1))
Select Case oVars("varLetter").Value
Case " ": oVars("varLetter").Value = "A"
Case "A"
oVars("varLetter").Value = "B"
sFname = Replace(sFname, " Revision A", "")
Case "B"
oVars("varLetter").Value = "C"
sFname = Replace(sFname, " Revision B", "")
Case "C"
oVars("varLetter").Value = "D"
sFname = Replace(sFname, " Revision C", "")
Case "D"
oVars("varLetter").Value = "E"
sFname = Replace(sFname, " Revision D", "")
Case "E"
oVars("varLetter").Value = "F"
sFname = Replace(sFname, " Revision E", "")
Case "F"
oVars("varLetter").Value = "G"
sFname = Replace(sFname, " Revision F", "")
Case Else: MsgBox "Maximum permitted revision already added." & vbCr & _
"Revision letter will not be updated" & vbCr & _
"Document will not be saved", vbInformation, "Revisions"
Exit Sub
End Select
For Each oStory In oDoc.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
oDoc.SaveAs sFname & " Revision " & oVars("varLetter").Value
End Sub


--

Graham Mayor - Word MVP

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





"UlfHJensen" wrote in message
...
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



.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross Referencing bookmarks created by a Userform Darren Ingram Microsoft Word Help 5 March 23rd 12 03:29 AM
Cross Referencing Bookmarks Brian Microsoft Word Help 3 May 12th 06 04:17 PM
Cross Referencing Mailmerge Bookmarks Brian Mailmerge 3 May 12th 06 05:09 AM
Referencing bookmarks in Word 2003 - how do I NOT bring the font i Tom McCray Microsoft Word Help 1 March 3rd 05 04:46 PM
Bookmarks and cross-referencing..what am I doing wrong? ~D~ New Users 3 January 16th 05 08:18 PM


All times are GMT +1. The time now is 03:09 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"