Consulting

Results 1 to 5 of 5

Thread: Using Application.Run

  1. #1
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location

    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?

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Sub AAA()
      Dim xlApp As Application
      
      Set xlApp = Application
      
      xlApp.Run "BBB"
    End Sub
    
    
    
    
    Sub BBB()
      MsgBox "Hello World"
    End Sub
    Artik

  3. #3
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    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?

  4. #4
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    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

  5. #5
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •