Unprotect & Protect Template

Z

zirac

I have a template with a dialogue box which will ask the name, address, etc
("lets") and have an option of OK or Cancel. The sytnax below works fine if
the user will select OK on dialogue box but an error will occur if it select
Cancel as there is no document open. So, no document to protect. Can you
please help me how will I get out with this.

Public Sub MAIN()


'Unprotect the document if protection not already disabled
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="Zaphod"
End If

WordBasic.call "lets"


'Protect the document if protection not already enabled
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Password:="Zaphod", _
NoReset:=False, _
Type:=wdAllowOnlyFormFields
End If

End Sub
 
S

Shauna Kelly

Hi zirac

Try something like this:

If Word.Application.Documents.Count > 0 then
' put all your existing code here
Else
msgbox "Sorry, we can't work unless you have a document open"
End If

Hope this helps.

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

Russ

Sorry, that I repeated an answer. MY messages were temporarily sorted by
name and not by the usual time and I thought the question had just come in
and was unanswered.
 

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