Results 1 to 4 of 4

Thread: open password protected Excel file

  1. #1

    Thread Starter
    Lively Member cargobay69's Avatar
    Join Date
    Nov 2001
    Location
    Kessel Prison Camp
    Posts
    97

    Question open password protected Excel file

    I would like to write code that will open an MS Excel file through code. The address will be hard coded into the program. I know to use Shell(), but the excel file is password protected and I would like to send the password to the file via code so the user doesn't have to enter it. Can it be sent via a command line switch? If so, what is the switch and syntax? If not, is there another way (aside from SendKeys())?
    I know what you are thinking "why have a password in the first place if you don't want the user to use it?". Well, that's a valid question, but the answer is a long story that I'd rather not get into.
    Any help is greatly appreciated.

    Thanks,
    Darrin@CB69
    -----------------------------------------------
    Arrogance kills brain cells
    -----------------------------------------------
    Private Sub Sandwich (big As Byte)
    On Error GoTo Pub

  2. #2
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    It's a reasonalbe thing to pwd-prot a file so you can make a restricted front end. I've only ever done this with Access, where I send the password through an ADO connection string.
    Haven't done it with Access.

    Can ADO access Excel??
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  3. #3
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Add a reference to the Microsoft Excel object library (versions may vary) and then use this:
    VB Code:
    1. Dim strPath As String
    2.     Dim strPass As String
    3.    
    4.     strPath = "c:\MyWorkbook.xls"   'Make this the path of the spreadsheet
    5.     strPass = "1234567890"  'Make this the password
    6.  
    7.     Dim XlApp As New Excel.Application
    8.     XlApp.Workbooks.Open strPath, , , , strPass
    9.     XlApp.Visible = True
    Obviously you'll have to modify the strPath and strPassword vars to suit your purpose.

    Hope this helps,
    Nishant

    You just proved that sig advertisements work.

  4. #4

    Thread Starter
    Lively Member cargobay69's Avatar
    Join Date
    Nov 2001
    Location
    Kessel Prison Camp
    Posts
    97

    Smile many tanks

    sounds good, i will try it

    thanks for your help
    Darrin@CB69
    -----------------------------------------------
    Arrogance kills brain cells
    -----------------------------------------------
    Private Sub Sandwich (big As Byte)
    On Error GoTo Pub

Posting Permissions

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



Click Here to Expand Forum to Full Width