Macro not found error

SpiderSpartan

New Member
Joined
Feb 13, 2009
Messages
7
I have a master workbook with a macro that runs through each open workbook running a sub called TrendMacro(). For some reason I keep getting the error "The macro 'workbook2.xls!TrendMacro' cannot be found." The macro 'TrendMacro()' definitely exists in the module for workbook2. I thought maybe the workbook was protected or locked, but it's not. Anyone know why else this could be happening?:confused: Thanks.

Here's the macro from the master workbook.
Code:
Sub TrendAll()
Dim Wkb As Workbook
    
    ReDim ErrBooks(0 To 0)
    
    For Each Wkb In Workbooks
        Application.Run (Wkb.Name & "!TrendMacro")
    Next Wkb
End Sub

Here's the macro from workbook2
Code:
Sub TrendMacro()
    'This Sub is part of the 'TrendAll' macro.
    MsgBox "DailyCellBBH Trending"
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I think I figured it out. The 'Application.Run' function must not like spaces in the name. I changed the workbook name from 'Workbook 2' to 'Workbook_2' and it ran no problem. So, now that that's been figured out, does anyone know how to make 'Application.Run' accept workbook names with spaces. I'm afraid that there may be other macros that mention the workbook by name and I don't want to mess them up by changing it if I can avoid it. Thanks.
 
Upvote 0
Enclose the name in single quotes.
Like this:
Code:
    Application.Run ("'" & Wkb.Name & "'!TrendMacro")
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

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