Consulting

Results 1 to 8 of 8

Thread: VBA to toggle "Show field codes insted of their values"?

  1. #1
    VBAX Regular YossiD's Avatar
    Joined
    Jan 2009
    Posts
    33
    Location

    VBA to toggle "Show field codes insted of their values"?

    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.

  2. #2
    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.

  3. #3
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    126
    Location
    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:

    Sub AutoOpen()
        ' Charles Kenyon 2023-Oct-25
        'Turns of display of field codes upon opening any document
        ActiveWindow.View.ShowFieldCodes = False
    End Sub
    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.
    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.

  4. #4
    Quote Originally Posted by Chas Kenyon View Post
    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
    dinosaur game

    Note that although it is about the ActiveWindow object, it actually toggles the option setting.

    I have the following macro in my Normal.dotm:

    Sub AutoOpen()
        ' Charles Kenyon 2023-Oct-25
        'Turns of display of field codes upon opening any document
        ActiveWindow.View.ShowFieldCodes = False
    End Sub
    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.
    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.
    Oh now I just learned about these shortcuts. Thank you.

  5. #5
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,400
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

  6. #6
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    126
    Location
    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.




    P.S. I know that you, Greg, know this stuff. You've taught me more about fields and vba than just about anyone.

  7. #7
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,400
    Location
    Charles,
    Like you, I'm learning everyday. Thanks for the enhancement on my post.
    Greg

    Visit my website: http://gregmaxey.com

  8. #8
    Banned VBAX Newbie
    Joined
    Mar 2024
    Posts
    1
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •