win32.com problem to unprotect a word document

Discussion in 'Python' started by Christian Lehmann, Nov 10, 2003.

  1. 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
     
    Christian Lehmann, Nov 10, 2003
    #1
    1. Advertising

  2. Christian Lehmann

    Peter Hansen Guest

    Christian Lehmann wrote:
    >
    > 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
     
    Peter Hansen, Nov 10, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    432
    Christian Lehmann
    Nov 11, 2003
  2. srk
    Replies:
    0
    Views:
    693
  3. srk
    Replies:
    0
    Views:
    647
  4. Michael G. Schneider

    Modifying a Word document without using Word Automation

    Michael G. Schneider, Dec 15, 2003, in forum: ASP General
    Replies:
    5
    Views:
    325
    el.c. - myLittleTools.net
    Dec 16, 2003
  5. deepakp
    Replies:
    1
    Views:
    782
    A. Sinan Unur
    Mar 3, 2006
Loading...

Share This Page