Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am opening Word but despite having VBA to open it as read only, it still allows editing and option for resaving.

    In my code I have:

    'Create an instance of MS Word
    Set WD = CreateObject(Class:="Word.Application")

    ' 'Open the Document
    WD.Documents.Open Filename:=LWordDoc, ReadOnly:=True


    and at the end have:

    WD.ActiveDocument.Saved = True, which stops the normal dialogue that comes up asking if you want to save the document (even though it's only been opened)

    How can I kill the problem once and for all? Thanks












    WD.ActiveDocument.Saved = True

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    The ReadOnly on Open option does permit editing and saving the document under another name, so that won't help.

    One thing that might work would be to apply some form of Protection to the document when you open it - starting in Word 2003, you can apply Read-Only protection to a document after it has been opened, so a line of code like:

    WD.ActiveDocument.Protect wdAllowOnlyReading

    would protect the document from editing. You can also add a a password to the protection.
    The document could still be resaved, but the resaved document would still be protected.

    In earlier versions of Word, you could use "Forms" protection instead:

    WD.ActiveDocument.Protect wdAllowOnlyFormFields

    which would do pretty much the same thing.

    Only catch with either of the above is that you wouldn't want the applied protection to be saved with the document when the user finally closes it, so you'd need to figure out a way to prevent that.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Gary.

    I put the line WD.ActiveDocument.Protect wdAllowOnlyReading at the end of my code, as the document gets certain keywords highlighted before the user sees it.

    I attempted to edit it, and MSWord was only too pleased to show the user how to overide read only. What a game?
    Attached Images Attached Images

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    The way Word presents that pane is misleading, in that it says the document is password-protected, whether it is or not. If no password was applied at the time the Read-Only protection was applied, then the user will see this screen, and they will be able to turn off the protection by clicking on the 'Stop Protection' button.

    However, if you password-protect the Read-Only protection, then Word may present those options to the user, but they won't be able to do anything without the password - try code like this:

    WD.ActiveDocument.Protect Type:=wdAllowOnlyReading, Password:="passwordstring"

  5. #5
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many, Many thanks Gary. That problem has been a pain in the neck.

    I put in your line, followed by WD.ActiveDocument.Saved = True. which took away the "Do you want to save" dialogue, and it did not save it passworded, and hey it works. Very greatful, regards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •