Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Amersfoort, Utrecht, Netherlands
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error on protected document (US/WD/97)

    Hello all,

    I have a little understanding from VBA, but try to solve a problem we have here running a printer macro.
    The macro is checking an external file for some printersettings of the first and other tray settings, then it will print the current documents with the correct settings.

    The macro is working perfectly..... until it should print a protected document. Then it comes with an error 13 message.
    Without sending the macro, could someone tell me if there is a differance handeling protected and unprotected documents in macro's?
    I could unlock the form in the macro, but when I relock it, will I loss all the data?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: error on protected document (US/WD/97)

    Since you mention WD in the header, I assume this is about Word.

    A Word document can be protected for Revisions, Comments and/or Form fields. In the first and second case, you can safely unprotect/protect the document. In the latter case, the standard unprotect/protect commands will reset all form fields. To do it safely, use code like the following:

    ActiveDocument.Unprotect [Password:="bla bla"]
    ' Modify settings and print here
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True [, Password:="bla bla"]

    The square brackets [ and ] mean that the password is optional. If the document has been protected with a password, you will need to provide it in both Unprotect and Protect.

    There is also the possibility that a document-level password has been set for the document. In that case, you have to provide it when you open it. Look up the Open method in the online help.

  3. #3
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Amersfoort, Utrecht, Netherlands
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error on protected document (US/WD/97)

    Hello Hans,

    Yes, Word it is.
    Thanks for the reply. Just one question... How do I check if the template is locked, because we use here locked and unlocked templates

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: error on protected document (US/WD/97)

    If you open a template as a document, you can check the ProtectionType property. It can have one of the following values: wdAllowOnlyComments, wdAllowOnlyFormFields, wdAllowOnlyRevisions or wdNoProtection.

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: error on protected document (US/WD/97)

    Patrick,

    When you use the terms locked and unlocked, do you mean protected and unprotected?

    You can check a document's protection type with code like this:

    If ActiveDocument.ProtectionType = wdNoProtection Then
    'do page setup code
    'print document
    Else 'document is protected
    'print document without having run page setup code
    End If

    - if a document is protected, you cannot change anything related to page setup (well, at least that is the case with forms protection; haven't checked the other types of protection), so that will cause an error if you try to do something to page setup via code.

    Gary

  6. #6
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Amersfoort, Utrecht, Netherlands
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error on protected document (US/WD/97)

    Thank you all,

    Your solutions will help me.

Posting Permissions

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