ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Call a VBA module from Microsoft Access (https://www.excelbanter.com/excel-programming/379697-re-call-vba-module-microsoft-access.html)

Nick Hodge

Call a VBA module from Microsoft Access
 
Freddy

The answer is certainly yes, but you will get better answers in an Access
group. this one is Excel

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Freddy" wrote in message
...
Is it possible to call a Visual Basic module from a Microsoft Access
database? Does anyone have sample code? My goal is to create a user menu
interface whereby different VBA modules are called depending on a button
that
is "clicked" on an Access menu.



Nick Hodge

Call a VBA module from Microsoft Access
 
Freddy

That may be tricky, automating Excel from VBA modules in Access would almost
certainly be possible

You are clicking a menu in a toolbar in Access, what are you then looking
for Excel to do?

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Freddy" wrote in message
...
Just for clarity, my plan is to call VBA modules written in Microsoft
Excel
from a Microsoft Access menu interface. Is your answer still the same?

"Nick Hodge" wrote:

Freddy

The answer is certainly yes, but you will get better answers in an Access
group. this one is Excel

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Freddy" wrote in message
...
Is it possible to call a Visual Basic module from a Microsoft Access
database? Does anyone have sample code? My goal is to create a user
menu
interface whereby different VBA modules are called depending on a
button
that
is "clicked" on an Access menu.




Nick Hodge

Call a VBA module from Microsoft Access
 
Freddy

This code was in a module in Access, (Should be simple to set a toolbar in
Access to run a module). It starts Excel and fires a macro called test in my
personal.xls (I have truncated the path to my personal.xls for readability).
The module in personal.xls only showed a messagebox, so that will be the
next thing for you to handle.

This uses early binding so you will need to set a reference to the MS Excel
object library in the VBE in Access (Under ToolsReferences...)

Sub AutomateExcelFromAccess()
Dim xlApp As Excel.Application
Dim xlWb As Excel.Workbook
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlWb = xlApp.Workbooks.Open("C:\Users\...\XLSTART\Persona l.xls")
xlApp.Run "PERSONAL.XLS!test"
xlWb.Close SaveChanges:=False
Set xlWb = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub

Module in personal.xls

Sub test()
MsgBox "Run from Access"
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Freddy" wrote in message
...
I want Excel to run a custom Excel macro that's in my Personal.xls file.

"Nick Hodge" wrote:

Freddy

That may be tricky, automating Excel from VBA modules in Access would
almost
certainly be possible

You are clicking a menu in a toolbar in Access, what are you then looking
for Excel to do?

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Freddy" wrote in message
...
Just for clarity, my plan is to call VBA modules written in Microsoft
Excel
from a Microsoft Access menu interface. Is your answer still the same?

"Nick Hodge" wrote:

Freddy

The answer is certainly yes, but you will get better answers in an
Access
group. this one is Excel

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Freddy" wrote in message
...
Is it possible to call a Visual Basic module from a Microsoft Access
database? Does anyone have sample code? My goal is to create a user
menu
interface whereby different VBA modules are called depending on a
button
that
is "clicked" on an Access menu.





All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com