run macro in an other workbook

cazdealer

Board Regular
Joined
Mar 12, 2011
Messages
96
Hi,

Can I make run a macro that is written in an other workbook from another workbook.

for exemple,

in a module of main.xlsm, can I write something in that that would :

activate test.xlsm (assuming test.xlsm is already openned)
run macro Start1 (that is written in VBA of test.xlsm and not main.xlsm).

thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi cazdealer,

One way of doing it would be.

Put this in the WB Test.xlsm

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Cells(Target.Row, Target.Column) = 1 And Target.Row = 1 And Target.Column = 1 Then
Start1
Cells(1, 1) = ""
End If
End Sub

And this in your WB main.xlsm

Code:
Sub activateTest()
Workbooks("Test.xlms").Sheets("Sheet1").Cells(1, 1) = 1
End Sub

This assumes both WBs are open

When you run the Sub activateTest(), the Private Sub Worksheet_Change event in the Test WB picks up the acton and runs the Start1 macro.
 
Upvote 0
Another way: In the calling wb:
Rich (BB code):
Sub CallOtherWBMac()
    Application.Run "'New Microsoft Excel Worksheet.xls'!Module1.Test", ThisWorkbook.Name
End Sub
Rich (BB code):
Sub Test(msg As String)
    MsgBox "I was called from " & msg
End Sub
I included one arg being passed just to show. The single quotes and string construction is always the PITA to me...
 
Upvote 0
How do I modified this to make it work with my problem?
Can I wrote this below (modified) in my main.xlsm to start macro start1 from test1.xlsm?
Rich (BB code):
Sub CallOtherWBMac()
    Application.Run "'New Microsoft Excel Worksheet.xls'!Module1.Test", ThisWorkbook.Name
End Sub
I don't understand the New Microsoft Excel Worksheet.xls part...
 
Upvote 0
How do I modified this to make it work with my problem?
Can I wrote this below (modified) in my main.xlsm to start macro start1 from test1.xlsm?
Rich (BB code):
Sub CallOtherWBMac()
    Application.Run "'New Microsoft Excel Worksheet.xls'!Module1.Test", ThisWorkbook.Name
End Sub
I don't understand the New Microsoft Excel Worksheet.xls part...

That was just the name of the new file I created to test. You would have something like: "test.xlsm!Module1.start1", where Module1 needs to be the name of the Standard Module that you have the procedure start1 housed in.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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