null protected document/ unique referrence

  • Thread starter OTWarrior via OfficeKB.com
  • Start date
O

OTWarrior via OfficeKB.com

I have a document that is protected so the user cannot enter information in
any place i don't want them to. When the form is saved, I have a macro to
input a unique reference in a text box (which unprotects the document and
protects it again, obviously)

The problem is I need to save the fomr for use, without running the macro. If
I unprotect the document and save, it should protect the document on save
anyway. However, I am not sure how to test that a document is protected, so
cannot test for a null value of it.

Long story short, how do I test that a document is protected?

NB: I did try the following, but to no avail.

If ActiveDocument.Protect = True Then
ActiveDocument.Unprotect Password:="password"
Else
Exit Sub
 
O

OTWarrior via OfficeKB.com

here is the full code for the macro i want to run:

Public Sub FileSave()
Dim oDoc As Document

Set oDoc = ActiveDocument
If oDoc.ProtectionType <> wdNoProtection Then
oDoc.Unprotect Password:="password"
Else

On Error Resume Next

Selection.GoTo What:=wdGoToBookmark, Name:="UIDBLANK"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.TypeText Text:=ComputerName & ": " & Now()
Selection.MoveLeft Unit:=wdCharacter, Count:=37, Extend:=wdExtend
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="UID"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With

ActiveDocument.Protect wdAllowOnlyFormFields, , ("password")

End If

'Selection.GoTo What:=wdGoToBookmark, Name:="ManagerName"
On Error Resume Next
Dialogs(wdDialogFileSaveAs).Show

End Sub
 
S

Shauna Kelly

Hi

ActiveDocument.ProtectionType will give you the protection type. Look up
Word's VBA help to decode the return values.

Specifically, if ActiveDocument.ProtectionType = wdNoProtection, then the
document is not currently protected.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
O

OTWarrior via OfficeKB.com

That was perfect, thank you very much :)


Shauna said:
Hi

ActiveDocument.ProtectionType will give you the protection type. Look up
Word's VBA help to decode the return values.

Specifically, if ActiveDocument.ProtectionType = wdNoProtection, then the
document is not currently protected.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
here is the full code for the macro i want to run:
[quoted text clipped - 30 lines]
 
S

Shauna Kelly

I'm glad it helped.

Shauna

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


OTWarrior via OfficeKB.com said:
That was perfect, thank you very much :)


Shauna said:
Hi

ActiveDocument.ProtectionType will give you the protection type. Look up
Word's VBA help to decode the return values.

Specifically, if ActiveDocument.ProtectionType = wdNoProtection, then the
document is not currently protected.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
here is the full code for the macro i want to run:
[quoted text clipped - 30 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top