Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Open Excel File from Access
Rob Whitney 
   
3 years ago
I have an app that requires me to open several password-protected Excel files from VBA. I've used the following code:

   Dim wb2 As Workbook
  
   Set wb2 = Workbooks.Open(FileName:="myFile.xlsm", password:="myPassword")

The file opens, but prompts for a password.
What am I missing?

Thanks!
Rob
Adam Schwanz  @Reply  
           
3 years ago
Is the file normally read-only? You could try writeresPassword:="myPassword") or take it even further and try ReadOnly:=False as well
Rob Whitney OP  @Reply  
   
3 years ago
No, it's not a read-only. It's a full access password. I can open it from the Windows interface, and enter the password at the prompt. When I open it with the code above, the spreadsheet interface prompts for the password, but won't open until the password is successfully entered (in other words, it doesn't "see" the password passed via the command line).
Adam Schwanz  @Reply  
           
3 years ago
Yea, your's is the correct working syntax for a normal password excel file.

Did you try the writeres or readonly and see if it changed the behavior at all?

The only other thing I can think of right now is admin privileges on the machine maybe. Have you tried on other machines or other files? All do the same?
Rob Whitney OP  @Reply  
   
3 years ago
Tried moving to a different VM - same behavior. Looking at the parameters for Workbooks.Open, I found "WriteResPassword". Tried that; no change. Set ReadOnly:=False and IgnoreReadOnlyRecommended:=False. No joy. Then, I removed the password protection from the spreadsheet and re-saved it. Tried to open with:
Set wb2 = Workbooks.Open(FileName:="myFile.xlsm", password:="myPassword")
Now, spreadsheet doesn't open (can still open from Windows).
The reference I'm using is "Microsoft Excel 16.0 Object Library" - is that the correct reference? Is there a better library to use?
At this point, pretty much spinning my wheels.
Kevin Robertson  @Reply  
           
3 years ago
Have you tried using Late Binding instead?

    Dim objExcel As Object, objWB As Object
    Dim myFilename As String, myPassword As String
    
    myFilename = "Path To Your Excel File"
    myPassword = "Your Password"

    Set objExcel = CreateObject("Excel.Application")
    Set objWB = objExcel.Workbooks.Open(Filename:=myFilename, Password:=myPassword)
    objExcel.Visible = True
    objExcel.WindowState = 3 '1-normal ; 2-minimized ; 3-maximized

    Set objWB = Nothing
    Set objExcel = Nothing
Rob Whitney OP  @Reply  
   
3 years ago
Kevin,

PERFECT! Works Great!  THANK YOU!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/8/2026 9:21:31 PM. PLT: 1s