-
Using Application.Run
Is there a way to shorten "Application.Run"? By that I mean, I can dim WF as a WorksheetFunction and set it to = Application.WorksheetFunction, so that I can execute worksheet functions with just WF.istext, for example. Is there a way to accomplish the same thing for Application.Run?
-
Code:
Sub AAA()
Dim xlApp As Application
Set xlApp = Application
xlApp.Run "BBB"
End Sub
Sub BBB()
MsgBox "Hello World"
End Sub
Artik
-
Thanks. I should have tried that using Dim. I was trying to define it and set it via a Public Property and it was erroring out on me. You're right. It works when dimmed the way you demonstrate. I wonder why the same thing can't be defined via a Public Property?
-
It will be reinventing the wheel. :)
In standard module
Code:
Sub AAA()
Dim objApp As CAppRunner
Set objApp = New CAppRunner
Set objApp.GetApp = Application
objApp.RunMethod "BBB"
End Sub
Sub BBB()
MsgBox "Hello world"
End Sub
and in a class module named CAppRunner
Code:
Option Explicit
Private mappGetApp As Application
Public Property Get GetApp() As Application
On Error GoTo HandleExit
Set GetApp = mappGetApp
HandleExit:
End Property
Public Property Set GetApp(rData As Application)
On Error GoTo HandleExit
Set mappGetApp = rData
HandleExit:
End Property
Sub RunMethod(strMacroName As String)
mappGetApp.Run strMacroName
End Sub
Artik
-