Open password protected excel file

  • Thread starter Thread starter Opal
  • Start date Start date
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?
 
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!! :-)
 
Back
Top