Full Version: Initiate running an Access macro while in Excel sheet
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
dharrington
I have a report that is best run as a pivottable in Excel. The data for the pivottable is a query I created in Excel based on data in an Access database. Before the query runs, I have some data manipulation I do in Access through a series of update queries, all tied together in an Access macro.

Does anybody know of a way to tie the Access macro to a button in the Excel spreadsheet? I'm trying to make this simple for the user. I don't want them to have to open both the Access file and the Excel spreadsheet to get the job done.
Luceze
When you say Access macro do you mean a true access macro or a VBA subroutine.

If it is VBA this should work.

CODE
      Dim objAccess As Access.Application
      Set objAccess = CreateObject("Access.Application")
      objAccess.OpenCurrentDatabase ("C:\test.mdb")
      objAccess.Run "YourSub"
      objAccess.CloseCurrentDatabase
      Set objAccess = Nothing


HTH,
dharrington
It is in an Access macro, but I changed it to a subroutine, calling the macro so I could try your code in Excel. It didn't work. I've never really used VB in Excel. When I create a button on my spreadsheet, the only thing I can do to it is create a macro. Are you recommending adding this code to the macro of a button?
NateO
In the following thread I cover Macros, Subs, and the kitchen sink:

http://groups.google.com/group/microsoft.p...ad23d3b27d233d8

But note my conclusion, there's probably no need to call anything from Access, run it in-line from Excel, eh. wink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.