Update all fields in Word 2010 automatically
I want you to automatically update all fields in the document. I currently have a macro that is linked to F9. This macro updates all the fields in the header, footer, and all those in the main document.
Sub UpdateFields()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End Sub
Aside from setting a macro on each key, how would I go about it so that this macro is executed when the user types something?
For example, a user can place a field in a footer or header that shows the number of characters. If that were the case, I would like to see the character input field update as I type.
source to share
Here are the events in Word VBA:
For the app: https://msdn.microsoft.com/EN-US/library/office/dn320473.aspx
For the doc: https://msdn.microsoft.com/EN-US/library/office/dn320613.aspx
I would assume you are using the Application.WindowSelectionChange
(Occurs when the selection changes in the active document window) event : https://msdn.microsoft.com/EN-US/library/office/ff192791.aspx
Public WithEvents appWord As Word.Application
Private Sub appWord_WindowSelectionChange(ByVal Sel As Selection)
UpdateFields
End Sub
And if you need more information on this, you can find it here: https://msdn.microsoft.com/library/office/ff746018.aspx
source to share