Myriad_Rocker
Questioning Reality
- Local time
- Today, 10:04
- Joined
- Mar 26, 2004
- Messages
- 166
Hey all...I've spent several hours trying to get this to work. I've searched Google, tried multiple ways to get it done, but I just can't do it.
I have a set of code that opens another workbook. I know it's open and I can see that it's open. I even have a loop that checks to make sure the file is done opening. Then I call a sub to execute a macro in that workbook I just opened. Below is that sub.
The if statement is testing as true because MacroName does exist. But then when it hits the run, it says Subscript out of range!!! Every time...
I know the MacroName is correct because the code just above the run validates as True. Any help here? PLEASE?
This is where the error is being thrown...
Application.Run ("'" & ActiveWorkbook.Name & "'" & "!" & MacroName)
I've also tried this and it doesn't work:
ActiveWorkbook.Application.Run (MacroName)
I have a set of code that opens another workbook. I know it's open and I can see that it's open. I even have a loop that checks to make sure the file is done opening. Then I call a sub to execute a macro in that workbook I just opened. Below is that sub.
Code:
Public Sub RunPrePostMacros(MacroName)
If MacroName <> "" Then
'Checking to see if the macro (proc) even exists
If CBool(Len(ActiveWorkbook.VBProject.VBComponents(MacroName).Name)) = True Then
Application.Run ("'" & ActiveWorkbook.Name & "'" & "!" & MacroName)
'Wait for workbook to finish running macro
Do Until ActiveWorkbook.Application.Ready = True
'Do nothing, just wait
Loop
End If
End If
End Sub
The if statement is testing as true because MacroName does exist. But then when it hits the run, it says Subscript out of range!!! Every time...
I know the MacroName is correct because the code just above the run validates as True. Any help here? PLEASE?
This is where the error is being thrown...
Application.Run ("'" & ActiveWorkbook.Name & "'" & "!" & MacroName)
I've also tried this and it doesn't work:
ActiveWorkbook.Application.Run (MacroName)
Last edited: