Use a Macro "ONTO" another workbook

30percent

Board Regular
Joined
May 5, 2011
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I posted something similar previously but I wasn't able to solve the problem I had.

For example I have the following workbook up "run_Macro1.xlsm" and the following code in Module1 of the workbook.

Code:
Sub run_Macro_1()


Worksheets("Sheet1").Range("A1").Value = "I just ran macro 1"




End Sub


Sub run_Macro_2()


Worksheets("Sheet1").Range("A2").Value = "I just ran macro 2"




End Sub

I would like to run run_Macro_1 and run_Macro_2 ONTO another workbook, say "target_Wb.xlsm". so that Workbooks("target_WB").Worksheets("Sheet1").Range("A1").Value = "I just ran macro 1" and Workbooks("target_WB").Worksheets("Sheet1").Range("A").Value = "I just ran macro 2".

How do I do that?

Thank you!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
Sub run_Macro_1()
Workbooks("target_WB.xlsm").Worksheets("Sheet1").Range("A1").Value = "I just ran macro 1"
End Sub
Target_WB has to be open.
 
Upvote 0
Code:
Sub run_Macro_1()


Workbooks("C:\Users\Desktop\target_Wb.xlsm").Worksheets("Sheet1").Range("A1").Value = "I just ran macro 1"




End Sub


Sub run_Macro_2()


Workbooks("C:\Users\Desktop\target_Wb.xlsm").Worksheets("Sheet1").Range("A2").Value = "I just ran macro 2"




End Sub


Sub call_macro_1_n_2()


Application.Run "C:\Users\Desktop\target_Wb.xlsm!run_Macro_1"


End Sub

I have the above code and target_WB.xlsm open. However, when I run call_macro_1_n_2 I got the following error message:

Code:
Run-time error '1004'

Cannot run the macroC:\Users\Desktop\target_Wb.xlsm!run_Macro_1. The macro may not be available in this workbook or all macros may be disabled.
'
 
Upvote 0
Code:
Sub run_Macro_1()
Workbooks("target_WB.xlsm").Worksheets("Sheet1").Range("A1").Value = "I just ran macro 1"
End Sub
Target_WB has to be open.

I did have Target_WB open. However, I still get the error message.
 
Upvote 0
Is the destination workbook actually named "Target_WB.xlsm" ? (Try running this code : Workbooks("Target_WB.xlsm").Activate )

Does Target_WB.xlsm have a sheet named "Sheet1" ?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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