Open password protected excel file

O

Opal

Running Access 2003, I have the following code to open an
excel file:

Sub ExcelOpen()

Dim xlApp As Excel.Application
Dim xlWkb As Excel.Workbook
Dim xlWsh As Excel.Worksheet

On Error Resume Next
' reference open session of excel
Set xlApp = GetObject(, "excel.application")
If Err.Number <> 0 Then
' excel not already running
Err.Clear
On Error GoTo 0
Set xlApp = New Excel.Application
xlApp.Visible = True
End If
On Error GoTo 0

Set xlWkb = xlApp.Workbooks.Open("C:\My Documents\Andon
\NewDTTracking.xls")
Set xlWsh = xlWkb.Worksheets("Report")
xlWsh.Activate

'With xlApp
'If Not .UserControl Then
'' opened excel using code
'.Quit
'End If
'End With

Set xlWsh = Nothing
Set xlWkb = Nothing
Set xlApp = Nothing

End Sub


How can I amend it to open a file that is
password protected?
 
D

DStegon via AccessMonster.com

Ummm... just ADD the password in the .OPEN event.

expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password,
WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable,
Notify, Converter, AddToMru, Local, CorruptLoad, OpenConflictDocument)

If you go to your code and just type a "," after your filename you should see
all of the above and fill in as needed.

Set xlWkb = xlApp.Workbooks.Open("C:\My Documents\Andon
 
O

Opal

Ummm... just ADD the password in the .OPEN event.  

expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password,
WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable,
Notify, Converter, AddToMru, Local, CorruptLoad, OpenConflictDocument)

If you go to your code and just type a "," after your filename you shouldsee
all of the above and fill in as needed.

Set xlWkb = xlApp.Workbooks.Open("C:\My Documents\Andon















--
DS

Message posted viahttp://www.accessmonster.com- Hide quoted text -

- Show quoted text -

Thank you! That's so cool!! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top