[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Call a VBA module from Microsoft Access

freddy

12/19/2006 4:07:00 PM

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.
4 Answers

Nick Hodge

12/19/2006 4:10:00 PM

0

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
nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
www.nickhodge.co.uk


"Freddy" <Freddy@discussions.microsoft.com> wrote in message
news:9FDE2F61-9111-4E96-B6D8-4880CB567A67@microsoft.com...
> 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

12/19/2006 4:54:00 PM

0

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
nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
www.nickhodge.co.uk


"Freddy" <Freddy@discussions.microsoft.com> wrote in message
news:80C226DC-EAE6-457D-BAB7-A1291D9D7C6F@microsoft.com...
> 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
>> nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
>> www.nickhodge.co.uk
>>
>>
>> "Freddy" <Freddy@discussions.microsoft.com> wrote in message
>> news:9FDE2F61-9111-4E96-B6D8-4880CB567A67@microsoft.com...
>> > 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

12/19/2006 5:42:00 PM

0

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 Tools>References...)

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\Personal.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
nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
www.nickhodge.co.uk


"Freddy" <Freddy@discussions.microsoft.com> wrote in message
news:43B7E00F-B408-4FC2-AB5B-5A6544EAC670@microsoft.com...
>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
>> nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
>> www.nickhodge.co.uk
>>
>>
>> "Freddy" <Freddy@discussions.microsoft.com> wrote in message
>> news:80C226DC-EAE6-457D-BAB7-A1291D9D7C6F@microsoft.com...
>> > 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
>> >> nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
>> >> www.nickhodge.co.uk
>> >>
>> >>
>> >> "Freddy" <Freddy@discussions.microsoft.com> wrote in message
>> >> news:9FDE2F61-9111-4E96-B6D8-4880CB567A67@microsoft.com...
>> >> > 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.
>> >>
>>

freddy

12/19/2006 6:29:00 PM

0

I will review, test, and advise.

"Nick Hodge" wrote:

> 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 Tools>References...)
>
> 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\Personal.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
> nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
> www.nickhodge.co.uk
>
>
> "Freddy" <Freddy@discussions.microsoft.com> wrote in message
> news:43B7E00F-B408-4FC2-AB5B-5A6544EAC670@microsoft.com...
> >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
> >> nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
> >> www.nickhodge.co.uk
> >>
> >>
> >> "Freddy" <Freddy@discussions.microsoft.com> wrote in message
> >> news:80C226DC-EAE6-457D-BAB7-A1291D9D7C6F@microsoft.com...
> >> > 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
> >> >> nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
> >> >> www.nickhodge.co.uk
> >> >>
> >> >>
> >> >> "Freddy" <Freddy@discussions.microsoft.com> wrote in message
> >> >> news:9FDE2F61-9111-4E96-B6D8-4880CB567A67@microsoft.com...
> >> >> > 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.
> >> >>
> >>
>