PDA

View Full Version : Prevent macro from running if already in ShowFieldCodes



francozola25
07-15-2008, 12:26 PM
Hey i was wondering if someone could help me

I have a macro that runs when i open the document as normal. What it does is rename a FormField in a document.



Application.ScreenUpdating = False
CommandBars("Forms").Visible = True
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Title"
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
CommandBars("Forms").Visible = False
MsgBox "Field Code inserted. This will automatically update when user clicks & inserts entry."
Application.ScreenUpdating = True


I want to make sure that this macro cannot run if i am already in ShowFieldCodes.

Is there a way to do this

Nelviticus
07-16-2008, 01:20 AM
If Not ActiveWindow.View.ShowFieldCodes Then
' Your code here
End If

... should do it.