Hello,
How can I open a password protected excel using vba. Can this be done using the GetObject method? I was using xlApp.Workbooks.open, but would like to try using GetObject.
Hi.
Assuming that you intend to run Your code from a standard excel file, if you want to open another excel file called, say, "Myfile.xls" which has 11111111 as password, this is the code.
Workbooks.Open Filename:="Myfile.xls, password:="11111111"
Hope this helps.
Bye
Nick
Hello,
I am running the code from an Access Macro. I have tried using variations of the following code -
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open FileName:="c:filepath\filename", Password:="whatever"
Set xlBook = xlApp.Workbooks.Add
Set xlSheet_MetLife = xlBook.Worksheets.Add
This code creates a new workbook instead of using the other workbook. If I omit the createobject line, it gives me an object variable not set error.
I have also tried -
Set xlApp = GetObject("c:\filepath\filename.xls")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet_MetLife = xlBook.Worksheets.Add
I was able to get it working using the following code. The only problem I have now is killing all objects. I seem to have one which I cannot identify that keeps an instance of Excel running in the background.
Thanks for all help
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = Workbooks.Open(FileName:="c:\filepath\filename", Password:="password")
Set xlSheet = xlBook.Worksheets.Add
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.