PDA

View Full Version : Changing Word-Tools-Options in VBA



Sandieslover
01-26-2005, 07:29 AM
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

Howard Kaikow
01-26-2005, 02:04 PM
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 .

Kelly
01-26-2005, 11:59 PM
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:

ActiveWindow.View.FieldShading = wdFieldShadingNever

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

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.

Sandieslover
02-02-2005, 12:56 AM
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

Jacob Hilderbrand
02-02-2005, 01:28 AM
Can you post an attachment of what you are working with so we can get a better idea of what you want to do?

Sandieslover
02-09-2005, 12:48 AM
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

Jacob Hilderbrand
02-20-2005, 08:03 AM
Sorry I didn't reply sooner, I missed your reply and just now noticed it. Would this work for you?

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


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

Aren't FORMTEXT fields always shaded?

TonyJollans
02-20-2005, 09:20 AM
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:
ActiveDocument.FormFields.Shaded = True ' or False

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

Howard Kaikow
02-20-2005, 01:15 PM
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.

EricFletcher
07-29-2020, 08:08 AM
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