View Single Post
 
Old 12-11-2014, 08:17 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

In order for the macro to be able to do anything in a protected form, you are going to have to include code to unprotect (and reprotect) the form. In your example:

Code:
Public Sub Test1()
Dim bProtected As Boolean
    'Unprotect the file
    If ActiveDocument.ProtectionType <> wdNoProtection Then
        bProtected = True
        ActiveDocument.Unprotect Password:=""
    End If
    With ActiveDocument.Content.Find
        .Text = "BOLD"
        .MatchWildcards = True
        .MatchCase = True
        .Replacement.Font.Bold = True
        .Execute Replace:=wdReplaceAll
    End With
    If bProtected = True Then
        ActiveDocument.Protect _
                Type:=wdAllowOnlyFormFields, _
                NoReset:=True, _
                Password:=""
    End If
End Sub
and note that your macro was called Test1 and not MyMacro ! Run Test1 on exit from the field. On Exit means when you leave the field, not when you select an item.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote