Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:53:28+00:00 2026-05-29T04:53:28+00:00

Note the tag: VBA , not VB6, not VB.NET. This is specific to VBA

  • 0

Note the tag: VBA, not VB6, not VB.NET.

This is specific to VBA in MS Access. I’ve built a collection of methods in an module I call “Enumerable”. It does a lot of things reminiscent of the Enumerable classes and interfaces in .NET. One thing I want to implement is a ForEach method, analagous to the .NET Enumerable.Select method.

I built a version that uses the Application.Run method to call a function for each element, but Application.Run only works with user-defined methods. For example, the following works:

' User-defined wrapper function:
Public Function MyReplace( _
    Expression As String, Find As String, StrReplace As String, _
    Optional Start As Long = 1, _
    Optional Count As Long = 1, _
    Optional Compare As VbCompareMethod = vbBinaryCompare)
    MyReplace = Replace(Expression, Find, StrReplace, Start, Count, Compare)
End Function

' Using Application.Run to call a method by name
Public Sub RunTest()
    Debug.Print Run("MyReplace", "Input", "In", "Out")
End Sub

RunTest prints “Output”, as expected. The following does NOT work:

Debug.Print Run("Replace", "Input", "In", "Out")

It throws run-time error 430: “Class does not support Automation or does not support expected interface”. This is expected, because the documentation states that Application.Run only works for user-defined methods.

VBA does have an AddressOf operator, but that only works when passing function pointers to external API functions; function pointers created using AddressOf are not consumable in VBA. Again, this is noted in the documentation (or see for example VBA – CallBacks = Few Cents Less Than A Dollar?).

So is there any other way to identify and call a method using a variable? Or will my callback-ish attempts be limited to user-defined functions via the Application.Run method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:53:29+00:00Added an answer on May 29, 2026 at 4:53 am

    No other answers in a week…for resolution’s sake here’s the best I could come up with:

    1. I built a helper module that resolves a ParamArray to individual arguments for the sake of calling CallByName. If you pass a ParamArray through to CallByName it will mash all the arguments into a single, actual Array and pass that to the first argument in the method you attempt to invoke.
    2. I built two ForEach methods: one that invokes Application.Run, and another that invokes CallByName. As noted in the question, Application.Run only works for user-defined global (public module) methods. In turn, CallByName only works on instance methods, and requires an object argument.

    That still leaves me without a way to directly invoke built-in global methods (such as Trim()) by name. My workaround for that is to build user-defined wrapper methods that just call the built-in global method, for example:

    Public Function FLeft( _
       str As String, _
       Length As Long) As String
        FLeft = Left(str, Length)
    End Function
    
    Public Function FLTrim( _
       str As String) As String
        FLTrim = LTrim(str)
    End Function
    
    Public Function FRight( _
       str As String, _
       Length As Long) As String
        FRight = Right(str, Length)
    End Function
    
    ...etc...
    

    I can now use these to do things like:

    ' Trim all the strings in an array of strings
    trimmedArray = ForEachRun(rawArray, "FTrim")
    
    ' Use RegExp to replace stuff in all the elements of an array
    ' --> Remove periods that aren't between numbers
    Dim rx As New RegExp
    rx.Pattern = "(^|\D)\.(\D|$)"
    rx.Global = True
    resultArray = ForEachCallByName(inputArray, rx, "Replace", VbMethod, "$1 $2")   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: I am not exactly sure how to title or tag this question, so
Note: Please do not tag this as homework! I am not a student and
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Note: Full code can be found at http://github.com/basicxman/andrewhorsman.net I have a Tag model and
Please note: This question relates to the Appcelerator Titanium platform, not the stock iOS
INITIAL NOTE: This is just for a personal tinkering project; I'm not writing enterprise
I am building a note taking app for myself with tag filtering functions, but
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note: This was posted when I was starting out C#. With 2014 knowledge, I
NOTE: I am not set on using VI, it is just the first thing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.