Getting fields updated in autonew macro

T

Tom Smith

I'm trying to create a memo template with a userform that will solicit the
recipient's name and the memo subject, and insert them (via 2 bookmarks)
into the memo. That much I have down, thanks to the article by Doug Robbins
on the MVP site.

What I'd also like to do is create a footer that would also list those items
of information. I've been trying to do this with 2 REF fields. Problem is,
the macro will run fine and fill in the bookmarks, but not put that info
into the REF fields. I've added a line in the code that should update the
fields (ActiveDocument.Fields.Update), but it doesn't seem to.

If I select the fields, in a document based on the template, and right-click
and use 'update fields,' they'll update.

Any idea where I'm going wrong? Would I be better advised just to put the
same bookmarks in the footer, rather than use REF fields at all?

Thanks much in advance. Tom
 
D

DA

Hi Tom

I don't think the ActiveDocument.Fields.Update will do an
update on fields in the headers and footers (similar to
doing select-all + F9).

Try the following, which should do the trick.

'--------------------
Sub fUpdte()
Dim sect As Section
Dim myHF As HeaderFooter

For Each sect In ActiveDocument.Sections
For Each myHF In sect.Headers
myHF.Range.Fields.Update
Next myHF
For Each myHF In sect.Footers
myHF.Range.Fields.Update
Next myHF
Next sect
End Sub
'---------------------

Hope that helps,
Dennis
 
T

Tom Smith

Dennis--many thanks. It worked perfectly, though I'm now left puzzling over
exactly what the 'range' part does. But thanks for the help. Tom
 
D

Doug Robbins

Hi Tom,

Depending on the version of Word, a document can be made up of up to 15
different story ranges of which that in which the main text of the document
is located is called the main story range. Some macro commands will only
operate on that story range and to get them to operate on the whole of the
document, it is necessary to address each story range.

For more on this, see the article "Using a macro to replace text where ever
it appears in a document
including Headers, Footers, Textboxes, etc." at:

http://word.mvps.org/FAQs/Customization/ReplaceAnywhere.htm


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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