Update Fields, VBA, nothing selected

K

Kelw

I have created a macro that takes over the functionality of the
shortcut for Updating fields (F9).

If any part of a certain section is selected when they press F9, I want
another macro to run, which it does successfully.

My problem is getting word to update fields as you would expect it to
normally using VBA.

You can normally put your cursor in any part or a field/TOC, and it
will update that field when you press F9.

If I record a macro, I get Selection.Fields.Update. If I use this in
VBA, it doesn't think that any fields are selected, so nothing gets
updated.

Can anyone help me to find out if the cursor is in a field, and to then
update the field if it is.

Many thanks, KelW
 
S

Stefan Blom

One way is the following:

Dim p As Paragraph
For Each p In Selection.Paragraphs
p.Range.Fields.Update
Next p

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 

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