Fields in Text Boxes

A

Alex

Hi Everyone

Posted this earlier this week on the Word programming
newsgroup but no replies, so trying here.


I've been using the following code to update the fields
in
my headers and footer.

Sub UpdateHF()
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter

For Each oSection In ActiveDocument.Sections

For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader

For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oField In oFooter.Range.Fields
oField.Update
Next oField
End If
Next oFooter

Next oSection

End Sub


However, I recently created a template that has a
floating textbox anchored to the footer, and within the
textbox is a custom doc property field. This doc
property field displays a manually entered version and is
in the textbox so I can display it as a Vertical
watermark on every page of the document. I know I can
specify watermark text in Word 2000, XP and 2003, but I
have the added problem of making it work on word 97,
hence the textbox method.

What I am finding is when the above code runs it updates
all the fields with the headers and footers except the
field within the textbox.

I changed the textbox to a frame and the code worked, but
unfortunately, frames have limited wrapping options and I
cannot place the frame behind text.

So my question is, can the above code be changed to
update the field within the textbox as well as all the
other fields within the headers and footers, and if so
how.

Regards

Alex
 
D

Doug Robbins - Word MVP

Hi Alex,

See the techniques used in the article "Using a macro to replace text where
ever it appears in a document including Headers, Footers, Textboxes, etc."
at:

http://www.mvps.org/word/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
A

Alex

Hi Doug

Thank you for the reply.
As VBA is the only aspect of Word that I'm still a
beginner on, I can see how the articled VBA works but have
no idea how to modify the code to update the fields in the
Textbox.

Is it a case of simply replacing the Find code with the
code I need to update the fields or is it a little more
complicated.

Any help you could give would be most helpful.

On a side note, could you recommend any books or
interactive CDs to help a VBA beginner get off the ground.

regards

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top