Consulting

Results 1 to 10 of 10

Thread: Changing Word-Tools-Options in VBA

  1. #1
    VBAX Regular Sandieslover's Avatar
    Joined
    Sep 2004
    Location
    Netherlands
    Posts
    14
    Location

    Exclamation Changing Word-Tools-Options in VBA

    Hi you all,

    how can I change the settings in the Tools-Options menu.
    I want for instance change the field shading, but the VBA recorder doesn't record this kind of actions.

    Please help,

    Regards,
    Sandieslover

  2. #2
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    How you do that depends on the particular options.

    Use the Object Browser to try to find the option and see if there is an example.

    A good place to start is Steve Roman's Writing Word Macros book (see http://www.standards.com/index.html?WordVBABooks .

    Also, take a look at http://www.standards.com/index.html?MacroRecording .

  3. #3
    VBAX Regular Kelly's Avatar
    Joined
    Jun 2004
    Location
    Los Angeles, California
    Posts
    84
    Hi Sandieslover,

    I'm using Word 2000, and I was able to record a macro that changed the field shading option. Of course, as with most recorded macros involving built-in dialog windows, the macro recorded EVERY setting displayed on the "View" tab of the "Options" dialog.

    So after deleting over 90% of the recorded macro, I'm left with:

    [vba]ActiveWindow.View.FieldShading = wdFieldShadingNever[/vba]

    **************************************

    Part Two:

    whoa, now here's something I never knew. I decided to test my little one-line macro, and I have found that the field shading setting doesn't affect 100% of the fields in my document. Interesting. I have never fooled around with this before.

    When I choose "Never" for field shading, my FORMTEXT fields all remain shaded.

    Only SEQ fields and REF fields in my document were "deshaded."

    I don't know if this relates to your original question or not. I guess there are some fields that cannot be deshaded.

  4. #4
    VBAX Regular Sandieslover's Avatar
    Joined
    Sep 2004
    Location
    Netherlands
    Posts
    14
    Location
    Hi Kelly,
    after trying your code line I stumbled into the same conclusion as you did.
    Then I read the end of your answere and I can only confirm your final conclusion.
    Hopelfully someone else knows the ins and outs of the why?
    Thanx for your time

    Regards,
    Sandieslover

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Can you post an attachment of what you are working with so we can get a better idea of what you want to do?

  6. #6
    VBAX Regular Sandieslover's Avatar
    Joined
    Sep 2004
    Location
    Netherlands
    Posts
    14
    Location
    Hi,

    as requested hereby an attachment. I hope it will explain to you what I want to do. Attached you will find a screendump of the options menu I'd like to alter via code.
    In the upper righthand corner you see the Field Shading option, with 3 possible options. When I open a document I want to store this setting and set this option automaticly to the option: When selected,so I have a black on white document without grey fields.
    On closing the document I want to restore this setting to it's opening value.

    I hope you can help me out, now I've made my wishes a bit more clear.

    Kind regards,
    Sandieslover

  7. #7
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Sorry I didn't reply sooner, I missed your reply and just now noticed it. Would this work for you?
    [vba]
    Option Explicit

    Dim Setting As Long

    Sub ChangeSetting()

    Setting = ActiveWindow.View.FieldShading
    ActiveWindow.View.FieldShading = wdFieldShadingAlways

    End Sub

    Sub ResetSetting()

    ActiveWindow.View.FieldShading = Setting

    End Sub
    [/vba]

    Call ChangeSetting in the Open event and ResetSetting on the Close event.

    Aren't FORMTEXT fields always shaded?

  8. #8
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    There are two different shading options - field shading and FORM field shading. Is this causing some confusion?

    Field Shading (non-form fields) is set via Tools > Options (or with code as already posted)

    Form Field Shading is set via the icon on the Forms Toolbar, or in code, by:
    [VBA]ActiveDocument.FormFields.Shaded = True ' or False[/VBA]

    Does that help at all? Or am I just muddying the waters as usual?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  9. #9
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Sandieslover
    Hi Kelly,
    after trying your code line I stumbled into the same conclusion as you did.
    Then I read the end of your answere and I can only confirm your final conclusion.
    Hopelfully someone else knows the ins and outs of the why?
    Thanx for your time

    Regards,
    Sandieslover
    my earlier response suggested that you would find your answer in the object browser.

    search for shade in the object browser and you will find your answer.

  10. #10
    VBAX Regular
    Joined
    Aug 2004
    Location
    On a 100 acre hobby farm in beautiful west Quebec.
    Posts
    87
    Location
    I just came across this old thread while looking for the same solution for how to toggle settings buried within the extensive Word Options dialog. After a bit of testing, I came up with this solution that works in the current version of Word (Office subscription model for Word as of July 2020 (version 2006 build 13001.20384).

    I thought I should post it here as reference for anyone else wanting to do something similar.

    Sub ToggleFieldCodeShading()
    '  Toggles field code shading on and off. EJF 2020-07-29
    '  Three different options can be set via the UI dialog (Word Options > Advanced > Show document content):
    '       0 = never apply (wdFieldShadingNever)
    '       1 = always apply (wdFieldShadingAlways)
    '       2 = apply only when selected (wdFieldShadingWhenSelected)
    '  The code below will toggle the field shading status between always and never,
    '  so if "when selected" is the current state, it will just toggle to "always".
    
    
    Dim CurrentState As Integer
    Dim dlgTOV As Dialog
    Set dlgTOV = Dialogs(wdDialogToolsOptionsView)
    CurrentState = dlgTOV.FieldShading
    
    If CurrentState = 0 Then
           CurrentState = 1
        Else
           CurrentState = 0
        End If
        
     With Dialogs(wdDialogToolsOptionsView)
        .FieldShading = CurrentState
        .Execute
        End With
        
    End Sub
    Last edited by EricFletcher; 07-29-2020 at 08:09 AM. Reason: adjusted formatting
    Eric

    Experience is not what happens to a man; it is what a man does with what happens to him. ? Aldous Huxley

Posting Permissions

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