Run macro only if doc is not protected

E

Elaine

I have the macro provided below which protects a document so that it cannot
be edited. However, when someone runs this file when it is already protected,
it gives an error message. I was wondering if someone could help me with a
statement that says something like:

If document is protected show message box indicating that document is
protected and when OK is clicked just go back to the document

If document is not protected then run the macro and save it to the M:\RayC
folder.

Thanks for your help.
===============

Sub Macro1()

'Protect Document
'Show File Open dialog box pointing to M:\RayC
'After user saves the file to a location Delete File from Original Location

Dim strdoc As String
strdoc = ActiveDocument.FullName

ActiveDocument.Protect Password:="raymondxc", NoReset:=False, Type:= _
wdAllowOnlyComments

'Show user File Open dialog box pointing to final replies and wait for him
to click OK

With Dialogs(wdDialogFileSaveAs)
.Name = "M:\RayC\" & ActiveDocument.Name
SendKeys "{Home}"
.Show
End With

'save file to do away with save changes dialog box
ActiveDocument.Save

'delete original file after it has been saved
Kill strdoc


End Sub
 
J

Jay Freedman

Hi Elaine,

Surround the ActiveDocument.Protect statement with an If ... End If
that tests the protection type, like this:

If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Password:="raymondxc", NoReset:=False, _
Type:=wdAllowOnlyComments
Else
MsgBox "The document is already protected."
Exit Sub
End If
 

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