View Full Version : [SOLVED:] 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?
Artik
08-08-2020, 09:56 AM
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?
Artik
08-09-2020, 02:45 AM
It will be reinventing the wheel. :)
In standard module
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
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.