Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Protected word document. Runtime error. How to detect? 1

Status
Not open for further replies.

christer99

IS-IT--Management
Joined
Dec 3, 2001
Messages
247
I have a Visual Basic program that copies/merges word document. However, some of the source documents are protected and I am getting this error:

System.Runtime.InteropServices.COMException (0x800A11FD): This method or property is not available because the document is a protected document.
at Microsoft.Office.Interop.Word.PageSetup.set_SectionStart(WdSectionStart prop)
at WindowsApplication8.Form1.CopyDocuments(String& docname, Int64 startpage, Int64 EndPage, Int64 DestPage, Int32 InsertPageBreak, Int32 vfAddon) in ...

I know I can use a try/catch statement, but how can I detect this specific error (protected documented). The COMException can be caused by a lot of things, and I want to be able to tell the end user that the source document is protected.
 
There are TWO types of protection.

A: the document itself is password protected for OPENING. You can catch this with:

If ActiveDocument.HasPassword = True

B: the document is protected for types of activity. The most common is protection for forms. In this case you can detect this when the document is opened.

If ActiveDocument.ProtectionType = wdNoProtection Then
'...continue on as there is no protection
Else
' message to user stating there is protection


You can unprotect with a password. If the password is incorrect, the user will get prompted. I am not sure how you could that at run-time.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top