Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Excel and run macro from Access

Status
Not open for further replies.

MikeCDPQ

Technical User
Sep 11, 2003
173
CA
I would like to have an Access script that would open an Excel workbook and call a script within excel.

I've tried different things that I saw here on the site but nothing seems to work.

Any suggestions anyone ?

Thanks for any help.

 
Hi MikeMcKesson,

This should do it ..

Code:
Dim appExcel As New Excel.Application
appExcel.Workbooks.Open
Code:
"C:\YourPath\YourWorkbook.xls"
Code:
appexcel.Run
Code:
"YourMacroInExcel"
Code:
appExcel.Quit
set appexcel = Nothing

You will need to have a reference to the Excel Object Library, and your Excel code in a Module in the Workbook you are opening.

Enjoy,
Tony
 
Hi Tony,

Well, not having too much luck. The very first line (Dim appExcel As New Excel.Application)

produces following error message:

Compile error:
User-defined type not defined

Really not overly familiar with VB yet so I don't quite know what that means. Any suggestions ?

Thanks a lot for your help.

Mike
 
Mike

You are writing your VBA in an Access Module right!!!

As Tony suggested, do this FIRST:

"You will need to have a reference to the Excel Object Library, in [the Access] Module." (not just the Worksheet as Tony said)

To do this,
Open your Access VBA code Module,
From the "Tools" Menu, Select References...
Scroll through the available refereces to find:
[] Microsoft Excel X.x Object Library

Click the checkbox then click Ok

Then Access should be able to understand the first line of the code.

(I'm not sure if you should restart access to ensure the reference is recognized, but I think not).



Zollo9999 A+
(Very Part-Time Programmer)
[thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top