Consulting

Results 1 to 2 of 2

Thread: Solved: Checking for protection

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Solved: Checking for protection

    I am trying to have some code check if various parts of my document are protected or not using the code below, I then want to unprotect the document and add to a bbokmark before re protecting the parts that were protected again

    My code always returns my first section is true (Protected) and the rest it returns nothing at all, can anyone tell me what im doing wrong here please

    cheers

    gibbo

    [VBA] Dim Section1 As String
    Dim Section2 As String
    Dim Section3 As String
    Dim Section4 As String
    If ActiveDocument.Sections(1).ProtectedForForms = True Then
    Section1 = "True"
    Else
    Section1 = "False"
    End If
    If ActiveDocument.Sections(2).ProtectedForForms = True Then
    Section1 = "True"
    Else
    Section1 = "False"
    End If
    If ActiveDocument.Sections(3).ProtectedForForms = True Then
    Section1 = "True"
    Else
    Section1 = "False"
    End If
    If ActiveDocument.Sections(4).ProtectedForForms = True Then
    Section1 = "True"
    Else
    Section1 = "False"
    End If
    On Error Resume Next
    ActiveDocument.Unprotect Password:="test"

    ActiveDocument.Bookmarks("Log").Range.Text = CreateObject("WScript.Network").UserName _
    & " Opened the application at " _
    & Format(Now, "hh:mm dd/mm/yy") & vbNewLine

    ActiveDocument.Sections(1).ProtectedForForms = Section1
    ActiveDocument.Sections(2).ProtectedForForms = Section2
    ActiveDocument.Sections(3).ProtectedForForms = Section3
    ActiveDocument.Sections(4).ProtectedForForms = Section4
    ActiveDocument.Protect Password:="test", NoReset:=False, Type:= _
    wdAllowOnlyFormFields [/VBA]

  2. #2
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    found this approach works for me

    Cheers for looking

    Gibbo

    [VBA] Dim sProtection
    ' Save Protection Status
    sProtection = ActiveDocument.ProtectionType
    If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
    ActiveDocument.Unprotect Password:="test"
    End If
    ActiveDocument.Bookmarks("Log").Range.Text = CreateObject("WScript.Network").UserName _
    & " Opened the application at " _
    & Format(Now, "hh:mm dd/mm/yy") & vbNewLine
    On Error Resume Next
    ActiveDocument.Protect Type:=sProtection, noreset:=True, Password:="test" [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •