Word 2010 - VBA Keypress
-
Monday, December 10, 2012 8:34 AM
Is it possible to create in my code for my document the key press required to update sum fields? If so can someone point me in a direction I can research further.
Thanks
Toni
Toni Chaffin aka Talisa
- Moved by Chester HongMicrosoft Contingent Staff Tuesday, December 11, 2012 6:27 AM (From:Windows Forms Data Controls and Databinding)
All Replies
-
Tuesday, December 11, 2012 6:26 AM
Hi TSRC,
Thanks for posting in MSDN.
According to your question, I would like to move your thread to Word for Developers forum for better support. There will be more experts to answer your question.
Sorry for any inconvenience.
Best regards,
Chester Hong
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Tuesday, December 11, 2012 7:18 AMModerator
Hi Toni
Can you tell us a bit more about the keypress functionality you require? Is this something that must be created by code? Or do you simply want a certain document to have a keyboard shortcut to a macro for updating Sum fields?
You do know that you can force all fields in your document (not just the Sum fields) to update by pressing Ctrl+A, then F9? (F9 will always update every field in a selection)
Cindy Meister, VSTO/Word MVP, my blog
-
Tuesday, December 11, 2012 9:29 AM
Further to Cindy's advice:
If you're using formfields in a document protected for forms, no code is needed - simply check the formfields' 'calculate on exit' option.
If you're using content controls, use a Document_ContentControlOnExit sub to update the fields (with ActiveDocument.Fields.Update)
Cheers
Paul Edstein
[MS MVP - Word]- Marked As Answer by TSRC Monday, December 17, 2012 1:37 PM
-
Monday, December 17, 2012 1:11 PM
Sorry for the delay. Thank you all for your contributions regarding this issue. I am working through your responses now.
Kindest Regards
Toni
Toni Chaffin aka Talisa
-
Monday, December 17, 2012 1:16 PM
The two fields that I wish to update are both contained within a table on the page. I use Forms and text boxes via Bookmarks to populate various fields via VBA on the document including a sub total of the required quotation. There are then two additional rows in the table that calculate the 20% VAT (TAX) and then a sum of the two previous rows to give a grand total.
I know I can use the Ctrl+A and then F9 but I am trying to get it to update the two fields on clicking OK on the user data entry form.
Does that make sense?
Toni
Toni Chaffin aka Talisa
-
Monday, December 17, 2012 1:23 PMModerator
Hi Toni
Thank you for the additional detail :-)
<<I know I can use the Ctrl+A and then F9 but I am trying to get it to update the two fields on clicking OK on the user data entry form.>>
In that case, try using Paul's suggestion - ActiveDocument.Fields.Update - at the end of the code triggered by the OK button in the UserForm.
Or, if you specifically want to update the fields in the table and no where else you can do something like:
ActiveDocument.Bookmarks("NameOfAnyBookmarkInTable").Tables(1).Range.Fields.UpdateCindy Meister, VSTO/Word MVP, my blog
- Marked As Answer by TSRC Monday, December 17, 2012 1:36 PM

