opening excel spreadsheet from access form

G

Guest

i've been on the threads for the last two days, and i'm not making any
headway. I want to place on an Access Form a button that launches an Excel
Spreadsheet. I see that this question is asked quite frequently, but all the
answers are not working for me. Here's what I'm doing:

Step One: I'm in the Design View of the Access Form
Step Two: I right-click on the button
Step Three: I select Build Event
Step Four: I click on Modules Folder and then right-click, and then scroll
down to Insert, then select Module
Step Five: I select Module1 from the folder
Step Six: I select Tools => References, and then I add Microsoft Excel Object
Step Seven: I ONLY add this code, nothing more:

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

Set appExcel = CreateObject("Excel.Application")
Set wbExcelFile = appExcel.Workbooks.Open("K:\Data Directories\test.xls")
wbExcelFile.Sheets("test").Select

Step Eight: I get an error that says: compile error: invalid outside procedure

Can you please give me the Entire code that I need, or if I'm doing
something wrong.
 
G

Guest

This will depend on what you are trying to do. If you just want to open an
existing spreadsheet for the user where there will be no interaction between
Access and Excel, all you need is the Shell() function.
If, on the other hand, you want to read data from or write data to the
spreadsheet, then you are on the right path, but off in the ditch. The code
you will need has to be either in the Click event of the command button, in
the form module at the top where you put subs and functions not attached to a
control, or in a standard module withing your database.
 

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