Open an Excel file with a button in Access

  • Thread starter Thread starter Anders Sjoman
  • Start date Start date
A

Anders Sjoman

Hi,

I would like to add a button to a form in Access 2003,
that opens a specific Excel file.

I have found the wizard that lets me open the Excel-
application -- but I cannot figure out how to specify
exactly which file to open.

Any ideas?

Many thanks,
Anders Sjöman
 
Hi, Anders.

Search VBA Help (<Ctrl>-G from database window, Help) for
the TransferSpreadsheet method. Syntax is:

expression.TransferSpreadsheet(TransferType,
SpreadsheetType, TableName, FileName, HasFieldNames,
Range, UseOA)

for example:

DoCmd.TransferSpreadsheet acImport, 3, _
"Employees","C:\Lotus\Newemps.wk3", True, "A1:G12"

HTH
Kevin Sprinkel
 
Hi Kevin,

Thanks for the advice -- this will actually help me solve
another problem I was struggling with.

However, this button should do something even simpler
than the TransferSpreadsheet method: just open a
specified file. (The TransferSpreadsheet method required
me to specify a query or range in a table in Access, and
it then overwrites the existing data in the Excel file,
so it won't help me in this particular place where I just
want to open a file.)

Any other ideas?

Thanks,
Anders
 
This works on my system to open a file called "c:test.xls":

Shell "C:\Program Files\Microsoft Office\Office10\excel.exe
c:\test.xls", vbNormalFocus

If the path to excel.exe is not exactly identical, that will fail.
 
Back
Top