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

Re: Update Fields, VBA, nothing selected by Stefan

Stefan
Mon Sep 11 08:27:15 CDT 2006

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


"Kelw" wrote in message
news:1157973447.771081.87700@q16g2000cwq.googlegroups.com...
> 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
>