Great, I did, thanks. Two questions:
-Why does only the function "activedocument.fields.update" not work?
-Is there a solution without using the text field (using only pure text on
the body)?
> -Why does only the function "activedocument.fields.update" not work?
Because although it sounds as if it will update /all/ the fields in the
document (and aI wish it did do that because everythign would be much
simpler), "activedocument.fields" only references the "main" story. (Well,
actually it may reference more stories than that, but that's what I think it
does).
> -Is there a solution without using the text field (using only pure text on
> the body)?
You could /probably/ do it by bookmarking the text (you could do this for
the header as well) and using the macro to replace the text. Because the
operation destroys the bookmark, you have to replace it. However, I haven't
tested it so don't take my word for it!
Let's suppose you have a bookmark on page 2 called page2bm and a bookmark in
the header called headerbm, then the following would probably do it:
Sub UpdateMyBMs()
UpdateBookmark "page2bm", ActiveDocument.Bookmarks("the name of your text
form field").Range.Text
UpdateBookmark "headerbm", ActiveDocument.Bookmarks("the name of your text
form field").Range.Text
End Sub
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
The above macro is adapted from Dave Rado's page at
http://word.mvps.org/faqs/macrosvba/InsertingTextAtBookmark.htm
Peter Jamieson
> Great, I did, thanks. Two questions:
> -Why does only the function "activedocument.fields.update" not work?
> -Is there a solution without using the text field (using only pure text on
> the body)?
Anderflash - 29 Jun 2007 18:22 GMT
Good, but if I replace the text field to a pure text, I will not have the
event 'on exit'. In other words, I don't have an event 'change' in the
document like worksheet_change from the excel and 'on exit' to the pure text.
In that case, I would need the user manipulation (a button or shortcut key)
to activate the bookmark's updating procedure.
But thanks for the information. I don't know if the Word VBA is too
important for me like Excel/Access VBA, but I liked the learning.
> > -Why does only the function "activedocument.fields.update" not work?
>
[quoted text clipped - 39 lines]
> > -Is there a solution without using the text field (using only pure text on
> > the body)?