Open Excel Spreadsheet

  • Thread starter Thread starter bob
  • Start date Start date
B

bob

Hi

This one must have been asked several times before, but I cannot find any
code that works. How do I open an existing Excel spreadsheet from Access
2003 using VBA. I do not want to do anything with the data in Excel, just
view it.

Thanks Bob
 
Dim blnReadOnly As Boolean
Dim objExcel As Object, objWorkbook As Object
Dim strPathFile as String
Dim strPassword As String

' Establish an EXCEL application object
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set objExcel = CreateObject("Excel.Application")
End If
Err.Clear
On Error GoTo 0

' Replace C:\Filename.xls with the actual path and filename
strPathFile = "C:\Filename.xls"

' Replace passwordtext with the real password;
' if there is no password, replace it with vbNullString constant
' (e.g., strPassword = vbNullString)
strPassword = "passwordtext"

blnReadOnly = True ' open EXCEL file in read-only mode

' Open the EXCEL file
Set objWorkbook = objExcel.Workbooks.Open(strPathFile, , blnReadOnly, , _
strPassword)
 
Back
Top