Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View Field Codes State in VBA

Status
Not open for further replies.
Joined
Aug 20, 2005
Messages
7
Location
GB
Is there anyway to determine the state of 'View Fields Codes' (as displayed using the Key combination Alt+F9) programatically in VBA and turn it on if it is off. Tried using Send Keys, but as this is a toggle it can all go horribly wrong. I want to combine this with a Multiple Document Search and Replace Macro that I already have (i.e. to allow me to replace field codes as well as body text).

Any ideas would be much appreciated.
 
Try

to switch them off:

ActiveWindow.View.ShowFieldCodes = False

and to switch them on:

ActiveWindow.View.ShowFieldCodes = True

Hope this helps.
 
EarthandFire,

Worked perfectly, many thanks.

Why is this not in the VBA help file (sorry not another question just a statement).

Thanks again
 
I didn't know how to do it.

The easiest way to solve problems like this with VBA in Word, Excel and PowerPoint (doesn't work in Access) is to record a macro to do whatever it is that you need and then take the code that the recorder produces.


Hope this helps.
 
Hi folks,

You can also use the ShowCodes Property for an individual field or for a series of fields via a loop.

Cheers
 
What version of Office do you have?

Fane Duru
 
In my case: "ActiveWindow.View.ShowFieldCodes = True" doesn't work (Office 2000). Is there a necessary reference?

Fane Duru
 
Hi FaneDuru,

Try something based on:
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True

For example, the following code snippet gets the current view state, stores it, displays field coding for whatever you want to do, then restores the original state:

Set fcDisplay = ActiveWindow.View
CurrSetting = fcDisplay.ShowFieldCodes
If CurrSetting <> True Then fcDisplay.ShowFieldCodes = True
' Do whatever
fcDisplay.ShowFieldCodes = CurrSetting

Cheers
 
Thanks, I tried it in Excel...that's why it did not work.

Fane Duru
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top