opening a specific spreadsheet in excel from an access form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am currently working in access, using a form, and I would like to create a
button which opens a specific spreadsheet in a specific excel workbook.
Currently I am using the following code to open the workbook:
Dim stAppName As String

stAppName = "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE
N:\SMDiv\Test\Reporting.xls\vehicle charts"
Call shell(stAppName, 1)

Exit_Command189_Click:
Exit Sub

Err_Command189_Click:
MsgBox Err.Description
Resume Exit_Command189_Click

End Sub
If there is a better way to do this, I would appreciate that as well
Thank you
 
Add a reference to the Microsoft Excel 10.0 Object Library and then:

Dim appExcel As Excel.Application
Dim wbExcelFile as Excel.Workbook

Set appExcel = CreateObject("Excel.Application")
Set wbExcelFile = appExcel.Workbooks.Open("N:\SMDiv\Test\Reporting.xls")
wbExcelFile.Sheets("vehicle charts").Select

'Optionally do other stuff with the workbook, including perhaps save and
close.
'Similarly you can quit Excel if you want.
'Alternatively you can just leave them open for the user to work with.
'Whatever you do, don't forget to release the object variables when you've
finished with them ...

Set wbExcelFile = Nothing
Set appExcel = Nothing
 
Back
Top