VB Update Field?

M

Mr. Esteban

Greetings-

As I am trying to make things for the end user as easy as possible, I
was wondering if a Macro or something of the sort could be made to
automatically update an includetext field in a .doc . I know and
understand that F9 or right-clicking updates the field, however,
leaving this responsibility to the end user is something that can be
quickly forgotten. I'd prefer the document/template itself to update
automatically to eliminate the risk of critical notices not being sent
out.

Thanks,

Mr. Esteban
 
C

Cindy Meister

A macro can certainly do this, the question is more: what should trigger it?

The simple solution is to update all the fields in the document text:

ActiveDocument.Fields.Update

Select and Bookmark the field, then update the fields in the bookmark is
also a one-liner

ActiveDocument.Bookmarks("TheName").Range.Fields.Update

If you want to target IncludeText fields in the document body, or in many
parts of the document (headers, footers, etc) that gets a bit more
complicated. If you need that, please specify exactly what you want.
 
M

Mr. Esteban

Thanks for your reply Cindy,

Exactly what I need is a document that automatically updates the
include text field when the document is opened. There is no problem at
all if the user is prompted to enable macros when opening the document,
however it needs to occur seamlessly and flawlessly after that,
insuring the proper disclaimer is sent.

Thanks Again,

Mr. Esteban
 
C

Cindy Meister

In order to get the code to execute when the document is opened, place it in
a macro named AutoOpen.
 
D

Doug Robbins - Word MVP

If the IncludeText field is in a template, then I would put the code in a
macro named AutoNew in the template. That macro will run whenever a new
document is created from the template.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

Mr. Esteban

Thanks Cindy and Doug,

I had some time to tinker with this project thanks to your guidance.
What I came up with is as follows:

Sub AutoOpen()
'
' AutoOpen Macro
' Updates all fields in document when opened
'
Selection.WholeStory
Selection.Fields.Update
Selection.HomeKey Unit:=wdStory
End Sub

I'm no programmer, and I don't think by anymeans this is pretty,
however, it works, and I'm pleased with the results. I hope this helps
someone along the way.

Thanks,

Mr. Esteban
 

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