• error on protected document (US/WD/97)

    Author
    Topic
    #370554

    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?

    Viewing 0 reply threads
    Author
    Replies
    • #586655

      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.

      • #586872

        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

        • #586878

          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.

        • #586880

          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

    Viewing 0 reply threads
    Reply To: error on protected document (US/WD/97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: