Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 5 of 5

Thread: Open a password protected word file with the password

  1. #1
    Join Date
    28th January 2003
    Location
    Perth, WA.
    Posts
    137

    Open a password protected word file with the password

    Hi all,

    I have a number of password protected Word templates that I need to open from within Excel using VBA.

    I use the following code to open the files but can not figure out how to send a password across?

    Any help would be appreciated.


    AJW

    VB:
    Sub wordtemp() 
        On Error Goto ErrorHandler 
        Dim wdApp As Word.Application 
        Dim MyDoc As Word.Document 
        Dim mywdRange As Word.Range 
        Set wdApp = New Word.Application 
        With wdApp 
            .Visible = True 
            .WindowState = wdWindowStateMaximize 
        End With 
        Set MyDoc = wdApp.Documents.Add("C:\Business\Force\TEMPLATES\New Templates\CONTRACT VARIATION .dot") 
        Set mywdRange = MyDoc.Words(1) 
        Exit Sub 
    ErrorHandler: 
        Set wdApp = Nothing 
        Set MyDoc = Nothing 
        Set mywdRange = Nothing 
        MsgBox ("Could not locate document") 
    End Sub 
    
    
    Edit: WillR - added code tags... please use them when posting code. Thanks

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    28th January 2003
    Location
    Solihull - England
    Posts
    8,678

    Re: Open a password protected word file with the password

    From reading the Help, (I'm no word expert) it seems you can open a password protected document using the open method & supplying the password as part of the open procedure.

    expression.Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenConflictDocument, OpenAndRepair , DocumentDirection, NoEncodingDialog)
    expression Required. An expression that returns a Documents object.

    FileName Required Variant. The name of the document (paths are accepted).

    ConfirmConversions Optional Variant. True to display the Convert File dialog box if the file isn't in Microsoft Word format.

    ReadOnly Optional Variant. True to open the document as read-only. Note This argument doesn't override the read-only recommended setting on a saved document. For example, if a document has been saved with read-only recommended turned on, setting the ReadOnly argument to False will not cause the file to be opened as read/write.

    AddToRecentFiles Optional Variant. True to add the file name to the list of recently used files at the bottom of the File menu.

    PasswordDocument Optional Variant. The password for opening the document.

    PasswordTemplate Optional Variant. The password for opening the template.

    Revert Optional Variant. Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.

    WritePasswordDocument Optional Variant. The password for saving changes to the document.

    WritePasswordTemplate Optional Variant. The password for saving changes to the template.

    Format Optional Variant. The file converter to be used to open the document. Can be one of the following WdOpenFormat constants.

    WdOpenFormat can be one of these WdOpenFormat constants.
    wdOpenFormatAllWord
    wdOpenFormatAuto The default value.
    wdOpenFormatDocument
    wdOpenFormatEncodedText
    wdOpenFormatRTF
    wdOpenFormatTemplate
    wdOpenFormatText
    wdOpenFormatUnicodeText
    wdOpenFormatWebPages

    To specify an external file format, apply the OpenFormat property to a FileConverter object to determine the value to use with this argument.

    Encoding Optional Variant. The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document. Can be any valid MsoEncoding constant. For the list of valid MsoEncoding constants, see the Object Browser in the Visual Basic Editor. The default value is the system code page.

    Visible Optional Variant. True if the document is opened in a visible window. The default value is True.

    OpenConflictDocument Optional Variant. Specifies whether to open the conflict file for a document with an offline conflict.

    OpenAndRepair Optional Variant. True to repair the document to prevent document corruption.

    DocumentDirection Optional WdDocumentDirection. Indicates the horizontal flow of text in a document.

    WdDocumentDirection can be one of these WdDocumentDirection constants.
    wdLeftToRight default
    wdRightToLeft

    NoEncodingDialog Optional Variant. True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.
    I used the following code successfully

    VB:
    Sub OpenDoc() 
        Documents.Open FileName:="C:\Will\Willy willy.dot", PasswordTemplate:="password" 
    End Sub 
    
    
    Kind Regards, Will Riley

    Web Presence:
    LinkedIn: Will Riley

  3. #3
    Join Date
    28th January 2003
    Location
    Perth, WA.
    Posts
    137

    Re: Open a password protected word file with the password

    WillR

    Thanks for the reply, my email notification needs to be updated.

    I tried your solution but came up with an error regarding the object.

    Did the following to resolve:

    Word.Application.Documents.Open ("C:\ TEMPLATES\CONTRACT VARIATION .dot"), passwordtemplate:="checkopen", Visible:=True

    Thanks for the pointers, greatly appreciated.

    AJW

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    23rd December 2003
    Location
    UK
    Posts
    122

    Re: Open a password protected word file with the password

    Quote Originally Posted by AJW
    Hi all,

    I have a number of password protected Word templates that I need to open from within Excel using VBA.

    I use the following code to open the files but can not figure out how to send a password across?

    Any help would be appreciated.


    AJW

    VB:
    Sub wordtemp() 
        On Error Goto ErrorHandler 
        Dim wdApp As Word.Application 
        Dim MyDoc As Word.Document 
        Dim mywdRange As Word.Range 
        Set wdApp = New Word.Application 
        With wdApp 
            .Visible = True 
            .WindowState = wdWindowStateMaximize 
        End With 
        Set MyDoc = wdApp.Documents.Add("C:\Business\Force\TEMPLATES\New Templates\CONTRACT VARIATION .dot") 
        Set mywdRange = MyDoc.Words(1) 
        Exit Sub 
    ErrorHandler: 
        Set wdApp = Nothing 
        Set MyDoc = Nothing 
        Set mywdRange = Nothing 
        MsgBox ("Could not locate document") 
    End Sub 
    
    
    Edit: WillR - added code tags... please use them when posting code. Thanks
    i wonder if i could ask the question on how this could be changed to open a passworded xl file so that info can be retrieved from the last cell in colum "A" and the resultant (from another file) row of figures returned to the file which is then updated closed and re-passworded.
    any help you can give would help resolve a problem i have inherited
    alexanderd

  5. #5

    Re: Open a password protected word file with the password

    Hi,

    If u really want to open your password protected word file then install (URL removed - advertising) software in your computer it will help u to open password protected file.
    It help me a lot i hope it also beneficial for u.
    Last edited by cytop; February 13th, 2012 at 05:59. Reason: Advertising...

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Forgotten Password For Password Protected Sheet
    By chathabox in forum EXCEL HELP
    Replies: 3
    Last Post: March 21st, 2007, 21:16
  2. ADO. Open Password Protected File
    By JosephSVK in forum EXCEL HELP
    Replies: 5
    Last Post: December 5th, 2006, 16:46
  3. Replies: 2
    Last Post: October 27th, 2005, 01:25
  4. VBA : how to read password protected file
    By s_u_resh in forum EXCEL HELP
    Replies: 1
    Last Post: April 18th, 2004, 02:00
  5. Passing password to protected files from another file
    By Jason_Moffitt in forum EXCEL HELP
    Replies: 4
    Last Post: March 31st, 2003, 14:58

Bookmarks

Posting Permissions

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