Results 1 to 4 of 4

Thread: [RESOLVED] Opening a Password-protected Excel Spreadsheet

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    3

    Resolved [RESOLVED] Opening a Password-protected Excel Spreadsheet

    I have been stuck for a few days. I need to keep one of my excel spreadsheets password-protected however I also need to manipulate that file through a VB script. If I try to open it, the script hangs while waiting for me to enter the password... I don't mind having the password typed in clear in my vb script, but I have not been able to pass this password to Excel so far...

    Can you help?

    Here is part of my code:

    Code:
    	Set objWorkBook = objExcel.Workbooks.open(oFolder.path & "\" &  oFile.Name)
    
    	objexcel.Visible = True 
    	objWorkBook.Refreshall 
    	objExcel.DisplayAlerts = FALSE	
    	objWorkBook.Save
    	objWorkBook.close true
    I tried objWorkBook.Password = mypassword
    and objExcel.Password = mypassword
    and neither worked.

    Thanks for any help!

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,440

    Re: Opening a Password-protected Excel Spreadsheet

    Welcome to VBForums

    The .Open method has several optional parameters, one of which is the password for the file, eg:
    Code:
    Set objWorkBook = objExcel.Workbooks.open(oFolder.path & "\" &  oFile.Name,Password:="YourPassword")

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    3

    Re: Opening a Password-protected Excel Spreadsheet

    THANKS, THANKS, THANKS!
    I spent my whole weekend on this issue.

    Finally, today I realized that I could ask someone!!! I guess although I'm not that old, I did not grow up in the 'internet' generation and don't necessarily think of checking forums. I will definitely bookmark this forum and make sure I visit it often from now on.

    Have a WONDERFUL day.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,440

    Re: Opening a Password-protected Excel Spreadsheet

    No problem, like many people here I'm happy to help.


    As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
    (this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved".

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