VBA Word hoe kan ik controleren of document beveiligd is

Status
Niet open voor verdere reacties.

xceland

Gebruiker
Lid geworden
29 feb 2012
Berichten
11
Als ik de volgende functie aanroep, terwijl het bestand niet beveiligd is, krijg ik een foutmelding.
Daarom wil ik vooraf afvragen of het document beveiligd is of niet.
De If-regel werkt niet, maar zoiets zoek ik.
Alvast bedankt.

Code:
Function vrijgeven()
    'If ActiveDocument.Protection = False Then Exit Function
    ActiveDocument.Unprotect ""
End Function
 
Bijna goed; je checkt verkeerd.
Code:
    If ActiveDocument.ProtectionType = wdNoProtection Then
        ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Else
        ActiveDocument.Unprotect
    End If
Overigens is dit voorbeeld letterlijk uit de Help te halen; die zit er niet voor niks bij ;)
 
de oplossing voor mij

Wat betreft de Helpfunctie: natuurlijk in gekeken, maar niet gevonden wat ik zocht.
Jouw oplossing klopt volgens mij niet helemaal, deze oplossing werkt voor mij:

Code:
Function BEVEILIGEN()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then Exit Function
    ActiveDocument.Protect wdAllowOnlyFormFields, , ""
End Function


Function VRIJGEVEN()
If ActiveDocument.ProtectionType = wdNoProtection Then Exit Function
    ActiveDocument.Unprotect
End Function
 
Mijn oplossing werkt prima, en houdt alles binnen éénf unctie. Een document is namelijk beveiligd, of niet. Je kunt dus echt met één functie af.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan