Is there a way to toggle the option "Show field codes instead of their values" in a macro? I could not find it in the Options object.
Is there a way to toggle the option "Show field codes instead of their values" in a macro? I could not find it in the Options object.
One option, though not very sexy, is using SendKeys; SendKeys statement (VBA) | Microsoft Learn. You can see which keys to use by pressing the Alt key and then they keyboard shortcuts to access each menu will display. Some items need a TAB and, like the Options menu, some need use of the ARROW keys. I did it just now and found that using this sequence brought me to that option:
F, T, 6 Down Arrows, TAB, F twice (you'll see that there are two options in the advanced settings that have an f underlined - denoting pressing f jumps to that setting) then pressing SPACE BAR to toggle the check mark.
There is also, just ALT + F9 to do it in the document that is open SendKeys "%{F9}" if you're not setting this for every document created in Word.
Last edited by jdelano; 10-22-2023 at 01:27 AM.
First, are you aware that there is already a bulit-in keyboard shortcut to do this. Windows Alt+F9 (Fn+Alt+F9 on many computers)
The following code will toggle the setting:
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Note that although it is about the ActiveWindow object, it actually toggles the option setting.
I have the following macro in my Normal.dotm:
Note that toggling, changing, this setting does not change what is displayed in open documents other than the active document until they are closed and reopened.Sub AutoOpen() ' Charles Kenyon 2023-Oct-25 'Turns of display of field codes upon opening any document ActiveWindow.View.ShowFieldCodes = False End Sub
If you have multiple documents open that you want changed do not apply it to each open document because you are changing a system, not a document setting. You might be able to do a screen refresh instead.
Last edited by Chas Kenyon; 10-25-2023 at 12:47 PM.
There is also a shortcut Shift+F9 that toggles the current field (or selected fields). Note: if this shortcut isn't working the you likely have another program which has taken over the Word shortcut.
Hi Greg,
Shift+F9 does not toggle the option, it is true.
That is a good thing in that you do not have to remember to toggle the settings back.
However, if the field is nested (one or more other fields inside the field) only the top (or outer) field layer is toggled. The internal nested fields just show their results.
Try Shift+F9 with one of Paul Edstein's calculated dates!
Also if you are trying to modify fields using vba, displaying the field coding usually works better, even with screen updating turned off.
- Function Keys and Keyboard Shortcuts that Manipulate Fields
- How to Toggle the Display of Field Codes in Word (my page)
P.S. I know that you, Greg, know this stuff. You've taught me more about fields and vba than just about anyone.
Charles,
Like you, I'm learning everyday. Thanks for the enhancement on my post.
To change from the field code to the merge field, or vice versa, in a Microsoft Word document: Press ALT + F9 to toggle Field Codes on/off.
Last edited by Aussiebear; 03-11-2024 at 09:16 PM. Reason: Removed the spam link