D
DavidRocastle
Hi i was wondering if anyone change help me. My code currently works on a
protected word document. I want the code to also execute if the document is
unprotected already. Would anyone know the if statement whereby if it is
protected then unprotect it else just carry on through the macro
Sub ChangeField()
'
' ChangeField Macro
' Macro recorded 19/06/2007 by ododd
'
ActiveDocument.Unprotect Password:="password"
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "FORMTEXT"
.Replacement.Text = "Title"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
ActiveDocument.Protect Password:="protect", NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
CommandBars("Task Pane").Visible = False
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
Dim answer
answer = MsgBox("Fields have now been updated", 65, "Document Control")
End Sub
protected word document. I want the code to also execute if the document is
unprotected already. Would anyone know the if statement whereby if it is
protected then unprotect it else just carry on through the macro
Sub ChangeField()
'
' ChangeField Macro
' Macro recorded 19/06/2007 by ododd
'
ActiveDocument.Unprotect Password:="password"
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "FORMTEXT"
.Replacement.Text = "Title"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
ActiveDocument.Protect Password:="protect", NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
CommandBars("Task Pane").Visible = False
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
Dim answer
answer = MsgBox("Fields have now been updated", 65, "Document Control")
End Sub