none
securing and unsecuing a Document using code. RRS feed

  • Question

  • I have documents stored in a folder on an OneDrive and they are protected by using:

      ActiveDocument.Protect Password:="Hello", NoReset:=False, Type:= _
            wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False

    And are unprotected by using: 

    ActiveDocument.UnProtect Password:="Hello"

    The documents are save as docx and docm, is there a way to protect or unprotect via code with the documents closed in a folder

    If the document is open and unprotected, is there programmable way to protect and unprotect using the structure of the security shown in this posting?

    Wednesday, January 27, 2016 8:41 PM

Answers

  • Hi, JimBassett

    Supported for   viewing and editing

    Supported only for   viewing 

    Cannot be opened 

    Excel workbook   (.xlsx)

    Portable Document   Format (PDF)

    Excel 97- Excel 2003   Workbook (.xls) **

    Excel binary   workbook file (xlsb)

     

    Excel 97- Excel 2003   Template (.xlt)

    Excel macro-enabled workbook (.xlsm)*

     

    Excel Template   (.xltx)

    OpenDocument   Spreadsheet file (.ods)

     

    Comma separated   values (CSV)

    IRM-protected   documents

    Password-protected   documents

    Documents with   digital signatures

    *The workbook can be opened, but macros do not run.

    **On OneDrive.com this format can be viewed. To edit, Excel Online saves a new copy of the document in .xslx format. Excel Online can’t save documents in the .xls format.

    For more information, click here to refer about Office Online File Support

    In addition if you have any feedbacks for Excel, please feel free to submit them to User Voice:

    https://excel.uservoice.com/

    Thanks for your understanding.

    • Marked as answer by David_JunFeng Friday, February 5, 2016 9:01 AM
    Monday, February 1, 2016 6:55 AM

All replies

  • Hi,

    This forum is for general questions and feedback related Microsoft Office. Since your question is more related to coding, I'll move it to the following forum for further assistance:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Steve Fan
    TechNet Community Support


    Please mark the reply as an answer if you find it is helpful.

    If you have feedback for TechNet Support, contact tnmff@microsoft.com.
    Thursday, January 28, 2016 6:40 AM
  • The kind of protection you're referring to is usually used for filling in forms; it won't prevent people opening them or modifying the contents of content controls, or printing them, though other editing will be precluded.

    Regardless of what kind of protection you want to apply, it has to be done by opening the files.

    The code you have posted is written for use on only the active document; it will not affect any other documents you may have open.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, January 28, 2016 10:06 AM
  • Thank you Paul!

    That is the desire protection.

    My question is in regards to documents on a OneDrive or SharePoint and being accessed by web version of Excel or Word. I can't manage security during open because there isn't any events like Open, Close, Save, SaveAs and such with the Web versions of Office.

    On the desktop I am able to run either the VBA I supplied with the document open and the document toggles between being secured or unsecured but I haven't been able to affect the security via a service that can modify the security state of an open Word or Excel file on the Web.

    Also I haven't been able to change the security setting and toggle the security stats on a desktop opened Word or Excel from a service either. I would think there would be a technique to modify the security state of an open (live) Word or Excel instance if the proper credentials were supplied. 

    Thank you again Paul!

    Thursday, January 28, 2016 3:13 PM
  • AFAIK, you would have to apply the security (using a desktop edition of Office, not a web edition) to the document before uploading to OneDrive or SharePoint. Obviously, though, you can't change the protection on the copy of a document someone else has open. If you're using a desktop edition of Office and have the right password to a document you have opened, you should be able to protect/unprotect it at will.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by David_JunFeng Friday, February 5, 2016 9:01 AM
    • Unmarked as answer by David_JunFeng Friday, February 5, 2016 9:01 AM
    Friday, January 29, 2016 1:23 AM
  • >>>Also I haven't been able to change the security setting and toggle the security stats on a desktop opened Word or Excel from a service either. I would think there would be a technique to modify the security state of an open (live) Word or Excel instance if the proper credentials were supplied.<<<

    According to your description, If I don't misunderstand, I suggest that you could use OpenXML SDK, this protection can be applied to a document using DocumentProtection tag. Once it is applied via Open XML, it can be found in word\settings.xml package part.

    For more information, click here to refer about How to set the editing restrictions in Word using Open XML SDK 2.0

    Friday, January 29, 2016 5:19 AM
  • Thank you David. I have been at the use of the OOXML SDK but didn't find what I thought I needed. You referring to protection tag and other simular protection information related to the OOXML is very helpful and a new starting point. Thank you!!
    Friday, January 29, 2016 5:27 AM
  • I am really interested in being able to modified the security setting in an open document or Workbook especially with the Web versions of Office applications. I suspect it is not possible at this time using the APIs that currently exist for Office Web applications and the lack of events like Open. save, saveas, etc. really makes it difficult.

    Thank you all for the very helpful information

    Jim


    • Edited by JimBassett Friday, January 29, 2016 4:35 PM
    Friday, January 29, 2016 4:34 PM
  • Hi, JimBassett

    Supported for   viewing and editing

    Supported only for   viewing 

    Cannot be opened 

    Excel workbook   (.xlsx)

    Portable Document   Format (PDF)

    Excel 97- Excel 2003   Workbook (.xls) **

    Excel binary   workbook file (xlsb)

     

    Excel 97- Excel 2003   Template (.xlt)

    Excel macro-enabled workbook (.xlsm)*

     

    Excel Template   (.xltx)

    OpenDocument   Spreadsheet file (.ods)

     

    Comma separated   values (CSV)

    IRM-protected   documents

    Password-protected   documents

    Documents with   digital signatures

    *The workbook can be opened, but macros do not run.

    **On OneDrive.com this format can be viewed. To edit, Excel Online saves a new copy of the document in .xslx format. Excel Online can’t save documents in the .xls format.

    For more information, click here to refer about Office Online File Support

    In addition if you have any feedbacks for Excel, please feel free to submit them to User Voice:

    https://excel.uservoice.com/

    Thanks for your understanding.

    • Marked as answer by David_JunFeng Friday, February 5, 2016 9:01 AM
    Monday, February 1, 2016 6:55 AM