win32.com problem to unprotect a word document

C

Christian Lehmann

Hello,

I´m trying to unprotect a word document with python for reading all form fields.
But it doesn´t work.

Here´s a simple code sample:


wordapp = win32com.client.Dispatch("Word.Application")
docfile = wordapp.Documents.Open(file)

protecttype = docfile.ProtectionType # protected delivers 2
docfile.Unprotect
protecttype = docfile.ProtectionType # anyway 2

# do some work

docfile.Protect
protecttype = docfile.ProtectionType # anyway 2


So someone please tell me, whats my fault?

best regards
Christian
 
P

Peter Hansen

Christian said:
I´m trying to unprotect a word document with python for reading all form fields.
But it doesn´t work.

Here´s a simple code sample:

wordapp = win32com.client.Dispatch("Word.Application")
docfile = wordapp.Documents.Open(file)

protecttype = docfile.ProtectionType # protected delivers 2
docfile.Unprotect
protecttype = docfile.ProtectionType # anyway 2

# do some work

docfile.Protect
protecttype = docfile.ProtectionType # anyway 2

So someone please tell me, whats my fault?

Is it possible you should actually be *calling* Unprotect
and Protect, instead of just retrieving their values?
To do that, make sure you include the parentheses as in

docfile.Unprotect()

Python is not VB...

-Peter
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top