opening a specific spreadsheet in excel from an access form

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
 
G

Guest

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
 

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