Run a Macro within a Macro

smashclash

Board Regular
Joined
Nov 24, 2003
Messages
126
Office Version
  1. 365
Platform
  1. Windows
I have a macro that performs tasks for a sheet. (Call it macro "X" for reference.) I have another macro (reference name Macro "Y") that runs macro "X" for every excel workbook that is open. I set this up in another workbook but want to transfer into my personal macro's file.

I copied everything into my file but when I try to run macro Y it gets an error because it can't find macro X. How do I tell Macro Y where to find macro X?


This is what the macro looked like before I moved the data:

Sub HideALL()
For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name Then
Windows(wb.Name).Activate ' new line - activate the wb first
Application.Run ("VeryHidden.xls!Hideone")
End If
Next wb
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,029
If both macros are in the same workbook, all you should need is to call HideOne without any other mumbo jumbo.

Code:
    HideOne
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,327
Messages
5,769,460
Members
425,550
Latest member
Bonebeast

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
Top