Running a Excel sheet macro from Access form button

haplc

Board Regular
Joined
May 27, 2004
Messages
71
Hello!

I have an excel sheet under d: \temp\test.xls with a macro named "makro1". This is a makro available in "all sheets". Now i have an Access form where I have a button with action I want to run MAKRO1 in excel sheet. I have used following script:(taken and modified from Mr. Excel--thanks)

Private Sub Befehl13_Click()

Dim xls As Object
Dim wrk As Object
Set xls = CreateObject("Excel.Application")
Set wrk = xls.Workbooks.Open("D:\temp\test.xls")
Rem xls.Run ("Makro1.Module3")(i have tried("Module3.Makro1"(
wrk.Close False
xls.Quit
Set xls = Nothing
End Sub

But from Access when I clicl the button, I have message: makro1 not found.

Also is it possible that after running the macro, the excel sheet may remain open??
thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
This is what you're looking for:

http://www.mvps.org/access/modules/mdl0007.htm

Here's the code segment. There's more description over there that's important. Yell if you need further explanation.

Code:
'This code was originally written by Dev Ashish
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Sub sRunCARMa()
Dim objXL As Object, x
    On Error Resume Next
    Set objXL = CreateObject("Excel.Application")
    With objXL.Application
        .Visible = True
        'Open the Workbook
        .Workbooks.Open "D:\CARM\SYS\CARMaV5\CARMaV5a.XLS"
        'Include CARMA in menu, run AutoOpen
        .ActiveWorkbook.RunAutoMacros xlAutoOpen
        x = .Run("AccountsViewEngine", 0)
    End With
    Set objXL = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,704
Messages
6,161,390
Members
451,701
Latest member
ckrings

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top