Stop VBA Evaluate from calling target function twice

Posted by Abiel on Stack Overflow See other posts from Stack Overflow or by Abiel
Published on 2010-04-10T01:55:47Z Indexed on 2010/04/10 2:03 UTC
Read the original article Hit count: 328

Filed under:
|

I am having trouble getting VBA's Evaluate() function to only execute once; it seems to always run twice. For instance, consider the trivial example below. If we run the RunEval() subroutine, it will call the EvalTest() function twice. This can be seen by the two different random numbers that get printed in the immediate window. The behavior would be the same if we were calling another subroutine with Evaluate instead of a function. Can someone explain how I can get Evaluate to execute the target function once instead of twice? Thank you.

Sub RunEval()
    Evaluate "EvalTest()"
End Sub

Public Function EvalTest()
    Debug.Print Rnd()
End Function

© Stack Overflow or respective owner

Related posts about vba

Related posts about excel