Open Excel Spreadsheet

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
 
K

Ken Snell

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)
 

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