Jump to content

How do I get the MS Word protection information using AutoIT?


Recommended Posts

I need to access the MS Word document protection information.

Open MS Word

Click on Developer tab (Other tabs that are also present are File, Home, Insert, Page Layout, References, Mailings, Review and View).

Click on Restrict Editing

On your right you will see a panel/frame "Restrict Formatting and Editing".

How do I access this text?

I am able to get to this step but then I am kind of lost on how to move ahead and fetch the data.

Example of the text that I am looking to access are ...

"Your permissions
This document is protected from unintentional editing.
You may edit in this region, but all changes will be tracked."
 
"Your permissions
This document is protected from unintentional editing.
You may only insert comments in this region."
 
"Your permissions
This document is protected from unintentional editing.
You may only fill in forms in this region."
 
"Your permissions
This document is protected from unintentional editing.
You may only view this region."
 
Thanks for your help
Anil
 
Link to comment
Share on other sites

  • Moderators

Are you looking to protect a document? Something like this should suffice:

 

#include <Word.au3>

$oWord = _Word_Create()
$oDoc = _Word_DocOpen($oWord, @DesktopDir & "\Test.doc")
Sleep(1000)
$oDoc.Protect(1)
Sets the doc to read only protection

Edit: See here for more info - http://msdn.microsoft.com/en-us/library/office/jj230379(v=office.15).aspx

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Correct, and as my example shows you can set that protection level. As the link I provided shows, you can set it to one of the following:

AllowOnlyComments

AllowOnlyFormFields

AllowOnlyReading

AllowOnlyRevisions

NoProtection

So, my question again is what exactly do you mean by "access" the protection level? Are you looking to set that level, or to determine what the level is?

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

You can query the protection type like this:

#include <Word.au3>

$oWord = _Word_Create()
$oDoc = _Word_DocOpen($oWord, @DesktopDir & "\Test.doc")
Sleep(1000)
;$oDoc.Protect(1)

MsgBox(0, "", $oDoc.ProtectionType)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks again.

Here are the return values I got for various protection types.

-1 / "Full access.docx" wdNoProtection / Do not apply protection to the document.
0 / "Insert comments and tracked changes only.doc" wdAllowOnlyRevisions / Allow only revisions to be made to existing content.
1 / "Insert comments only.doc" wdAllowOnlyComments / Allow only comments to be added to the document.
2 / "Fill in form fields only.doc" wdAllowOnlyFormFields / Allow content to be added to the document only through form fields.
3 / "Read only.doc" wdAllowOnlyReading / Allow read-only access to the document.
 
 
I wonder why the return value is -1 for a doc without any protection ... Is this expected?
Edited by anilshekhar
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...