none
Password Prompt in word 2010 RRS feed

  • Question

  • Hi,

    We have a VB application in which we use word templates. We create the docs with the password. We are doing this because, user should not open and edit the docs physically. User should edit the docs only using the application. When trying to print the doc ,it is asking for the password.

    This issue is not happening for other word versions. The issue is happening only in Word 2010. Below is the code used to print the doc from the application.

    objWord.PrintOut True, , , , , , wdPrintDocumentContent, , , , , , lstFilesInPool.Path + "\" + lstFilesInPool.List(x)

    Thanks,

    Krishna.


    Krishna Prakash
    • Edited by Krishna.133 Friday, May 27, 2011 2:21 PM changed the subject
    • Moved by Liliane Teng Monday, May 30, 2011 9:42 AM (From:Visual Basic IDE)
    Friday, May 27, 2011 2:20 PM

Answers

  • I was using the below code to print the documents.

    objWord.PrintOut True, , , , , , wdPrintDocumentContent, , , , , , lstFilesInPool.Path + "\" + lstFilesInPool.List(x)

    I removed the file name that is passed as part of calling the PrintOut Method and the issue seems to be resolved.

    New code will be,

    objWord.PrintOut True, , , , , , wdPrintDocumentContent, , , , , , ""


    Krishna Prakash
    Friday, August 5, 2011 2:12 PM

All replies

  • Hello Krishna.133,

    I moved this thread to Word for Developers forum which is more appropriate for this issue. Here you may get more better support, because more this aspect experts live there. Thanks for your understanding.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 30, 2011 9:45 AM
  • Hi Krishna

    If you're using PrintOut, then you're also using Documents.Open in your code, yes? And are you supplying the password in that method, or is that what's causing the prompt?


    Cindy Meister, VSTO/Word MVP
    Monday, May 30, 2011 10:19 AM
    Moderator
  • Hi Cindy,

    Thanks for your reply. Below is the complete code, we are using to print the document.

     

            For x = 0 To lstFilesInPool.ListCount - 1
                If lstFilesInPool.Selected(x) = True Then
                    objWord.Documents.Open lstFilesInPool.Path + "\" + lstFilesInPool.List(x), ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="xxxx", PasswordTemplate:="xxxxx", Revert:=False, WritePasswordDocument:="xxxx", WritePasswordTemplate:="xxxx", Format:=wdOpenFormatAuto
                    Sleep 100
                    objWord.ActivePrinter = EDMPrinter
                    objWord.Visible = False
                    objWord.ActiveDocument.PageSetup.FirstPageTray = wdPrinterLowerBin
                    objWord.ActiveDocument.PageSetup.OtherPagesTray = wdPrinterLowerBin
                    objWord.Visible = False
                    objWord.PrintOut True, , , , , , wdPrintDocumentContent, , , , , , lstFilesInPool.Path + "\" + lstFilesInPool.List(x)
                    objWord.Documents(lstFilesInPool.Path + "\" + lstFilesInPool.List(x)).Close
                End If
            Next

    When a list of docs are selected in the grid and click on print button in the application, above code is called. This will just print all the selected docs without opening the docs physically. All the things are carried out in background.

    Recently word2010 has been rolled out. When the user performs same operation, word 2010 is asking for the user to enter the password. Iam not sure about what changes in word2010 is causing the issues.

    Could you please provide your valuable suggestion.


    Krishna Prakash
    • Edited by Krishna.133 Monday, May 30, 2011 11:06 AM spelling mistake..
    Monday, May 30, 2011 11:05 AM
  • Hi,

     

    Your code seems to confuse me. Do you mean that you develop a VB.NET WinForm Application as I noticed that there are some keywords such as “grid”, “print button” and “VB application” in your description?

    However, you open a document via:

    objWord.Documents.Open lstFilesInPool.Path + "\" + lstFilesInPool.List(x), ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="xxxx", PasswordTemplate:="xxxxx", Revert:=False, WritePasswordDocument:="xxxx", WritePasswordTemplate:="xxxx", Format:=wdOpenFormatAuto
    

    You call a method in VB.NET without brackets?

    It seems to me that this phrase in only support in VBA. So would you like to tell us which you are using, VBA or VB.NET?

     

    I look forward to hearing of you.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 7, 2011 3:23 AM
    Moderator
  • Hi Calvin,

    We have a screen in our VB application which will provide the list of documents available for the user to print. User can select single or multiple files.

    All the docs used in our application are password protected.

    User will select single or multiple documents and clicks the PRINT button provided in our VB application. Then below code is executed to print all the selected documents. Below code will loop through the documents selected, and will print the document in background.(i.e) the document will not be visible to the user while printing.

            For x = 0 To lstFilesInPool.ListCount - 1
                If lstFilesInPool.Selected(x) = True Then
                    objWord.Documents.Open lstFilesInPool.Path + "\" + lstFilesInPool.List(x), ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="xxxx", PasswordTemplate:="xxxxx", Revert:=False, WritePasswordDocument:="xxxx", WritePasswordTemplate:="xxxx", Format:=wdOpenFormatAuto
                    Sleep 100
                    objWord.ActivePrinter = EDMPrinter
                    objWord.Visible = False
                    objWord.ActiveDocument.PageSetup.FirstPageTray = wdPrinterLowerBin
                    objWord.ActiveDocument.PageSetup.OtherPagesTray = wdPrinterLowerBin
                    objWord.Visible = False
                    objWord.PrintOut True, , , , , , wdPrintDocumentContent, , , , , , lstFilesInPool.Path + "\" + lstFilesInPool.List(x)
                    objWord.Documents(lstFilesInPool.Path + "\" + lstFilesInPool.List(x)).Close
                End If
            Next

    Believe i have explained your question. Let me know if you need more info.

    Is there any code to unprotect 2010 word document. Currently we are using objword.activedocument.unprotect command to unprotect the word document. But this does not work for word 2010.

    Thanks.


    Krishna Prakash
    • Edited by Krishna.133 Wednesday, June 8, 2011 8:09 AM Edited to provide more info
    Wednesday, June 8, 2011 7:16 AM
  • Hi Krishna,

     

    Thanks for your update.

    I know what you want to do and it seems that there is not logic error in your code. The only thing I can’t understand is which language are you using, VBA (Visual Basic for Application), VB.NET or VB6?

    The reason I want to know this is the calling a method without brackets is only allowed in VBA:

    Word.Documents.Open (FileName:=….)

     

    For your second question, protect & unprotect method in Word is used to protect document from some specific editing rather than encrypting and unencrypting a Word document.

     

    You can encrypt a document via SaveAs method.

    Note: the SaveAs method name change to SaveAs2 in Word 2010.

    Please refer to the code below:

            'clear password

            doc.SaveAs2(Password:="")

            'set a password

            doc.SaveAs2(Password:="hello")

     

    I hope this helps.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 8, 2011 9:19 AM
    Moderator
  • Iam using VB6 code to print the letters.

    Currently we are protecting and unprotecting the doc using the below code(VB6)

    objword.activedocument.unprotect "pwd"  -- To UnProtect

    objword.activedocument.protect wdAllowOnlyFormFields, True, "pwd" -- To Protect

    The above code works well till word2003, but this is not working with word 2010. Is there any way to achieve this.

            'clear password

            doc.SaveAs2(Password:="")

            'set a password

            doc.SaveAs2(Password:="hello")

    Will the above code will save the doc?

    I believe the below VB6 command also will not work for Word 2010. Is there any other way to modify the below command which will fit for word 2010

    objWord.Documents.Open lstFilesInPool.Path + "\" + lstFilesInPool.List(x), ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="xxxx", PasswordTemplate:="xxxxx", Revert:=False, WritePasswordDocument:="xxxx", WritePasswordTemplate:="xxxx", Format:=wdOpenFormatAuto

    Note : - All of my code is in VB6.


    Krishna Prakash
    Thursday, June 9, 2011 12:51 PM
  • Hi,

     

    Document.Protect method is used to protect a document from changes rather than adding a password for opening the document.

    SaveAs Method

    Password     Optional Variant. A password string for opening the document. (See Remarks below.)

    Protect Method

    Helps to protect the specified document from changes. When a document is protected, users can make only limited changes, such as adding annotations, making revisions, or completing a form.

     

    And the SaveAs method will save all the changes including programmatically and manually.

     

    In addition, why don’t you just try to migrate your project from VB6 to VB.NET, which maybe solve your issues. However, if you persist in VB6, I would recommend you to post your question in some VB6 forum as Microsoft doesn’t support for VB6 any more.

    Where to post your VB 6 questions

     

    I hope this helps.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 9, 2011 4:08 PM
    Moderator
  • Calvin.. Do u see any issues with the below code(This is a VB6 code).

    objWord.Documents.Open lstFilesInPool.Path + "\" + lstFilesInPool.List(x), ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="xxxx", PasswordTemplate:="xxxxx", Revert:=False, WritePasswordDocument:="xxxx", WritePasswordTemplate:="xxxx", Format:=wdOpenFormatAuto

    This code is working fine for all the versions of the word till word 2003. But this code doesn't work for word 2010.

    Thanks for your help.


    Krishna Prakash
    Friday, June 10, 2011 11:04 AM
  • I was using the below code to print the documents.

    objWord.PrintOut True, , , , , , wdPrintDocumentContent, , , , , , lstFilesInPool.Path + "\" + lstFilesInPool.List(x)

    I removed the file name that is passed as part of calling the PrintOut Method and the issue seems to be resolved.

    New code will be,

    objWord.PrintOut True, , , , , , wdPrintDocumentContent, , , , , , ""


    Krishna Prakash
    Friday, August 5, 2011 2:12 PM