PC Review


Reply
Thread Tools Rate Thread

Application.Evaluate question

 
 
lcsma
Guest
Posts: n/a
 
      11th Dec 2008
It seems like Application.Evaluate always evaluates the command twice.
I have a custom addin and want to write a macro to evaluate an addin
command. By setting a break point at my addin function, I can see that when
Application.Evaluate is evoked, it called the addin function twice. Is there
any way to disable this behaviour or is there any alternative to
application.evaluate that would only run the command once?

I am using excel 2002 SP3.

Thanks.

(PS. I cannot put the command in a cell and calculate because the
addin-function returns a variable-size array and I want to get the returned
array and do some additional processing on it.)

 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      11th Dec 2008
Why not just set the array equal to the return of the function? You may need
to set a reference to the project, but this should work:

Sub TestArrayReturn()
Dim myArr As Variant
Dim i As Integer
myArr = TestFunction
For i = LBound(myArr) To UBound(myArr)
MsgBox myArr(i)
Next i
End Sub

Function TestFunction() As Variant
TestFunction = Array(1, 2, 3)
End Function


HTH,
Bernie
MS Excel MVP


"lcsma" <(E-Mail Removed)> wrote in message
news:C474FBB4-F6F3-4C3A-B1B4-(E-Mail Removed)...
> It seems like Application.Evaluate always evaluates the command twice.
> I have a custom addin and want to write a macro to evaluate an addin
> command. By setting a break point at my addin function, I can see that
> when
> Application.Evaluate is evoked, it called the addin function twice. Is
> there
> any way to disable this behaviour or is there any alternative to
> application.evaluate that would only run the command once?
>
> I am using excel 2002 SP3.
>
> Thanks.
>
> (PS. I cannot put the command in a cell and calculate because the
> addin-function returns a variable-size array and I want to get the
> returned
> array and do some additional processing on it.)
>



 
Reply With Quote
 
lcsma
Guest
Posts: n/a
 
      12th Dec 2008
Thanks. I will try this approach. I had difficulty setting reference to the
add-in as it didn't show up in the Tools->References list, but I guess that's
a separate problem.

Out of curiosity, Is this behavior a well known feature of
Application.Evaluate? What's the reason that it needs to evaluate twice?

TIA

"Bernie Deitrick" wrote:

> Why not just set the array equal to the return of the function? You may need
> to set a reference to the project, but this should work:
>
> Sub TestArrayReturn()
> Dim myArr As Variant
> Dim i As Integer
> myArr = TestFunction
> For i = LBound(myArr) To UBound(myArr)
> MsgBox myArr(i)
> Next i
> End Sub
>
> Function TestFunction() As Variant
> TestFunction = Array(1, 2, 3)
> End Function
>
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> "lcsma" <(E-Mail Removed)> wrote in message
> news:C474FBB4-F6F3-4C3A-B1B4-(E-Mail Removed)...
> > It seems like Application.Evaluate always evaluates the command twice.
> > I have a custom addin and want to write a macro to evaluate an addin
> > command. By setting a break point at my addin function, I can see that
> > when
> > Application.Evaluate is evoked, it called the addin function twice. Is
> > there
> > any way to disable this behaviour or is there any alternative to
> > application.evaluate that would only run the command once?
> >
> > I am using excel 2002 SP3.
> >
> > Thanks.
> >
> > (PS. I cannot put the command in a cell and calculate because the
> > addin-function returns a variable-size array and I want to get the
> > returned
> > array and do some additional processing on it.)
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.Evaluate (works with SIN but not RGB) Matthew Herbert Microsoft Excel Programming 4 14th Jan 2010 12:36 AM
Application.Evaluate Carim Microsoft Excel Programming 13 7th Jan 2009 08:50 PM
evaluate function only in Excel application x taol Microsoft Excel Programming 1 17th Mar 2008 09:53 PM
Interpretation of Application.Caller.Parent.Evaluate FARAZ QURESHI Microsoft Excel Misc 1 29th Dec 2007 07:59 PM
Error 2015 with Application.Evaluate =?Utf-8?B?SmVmZg==?= Microsoft Excel Programming 3 6th Jun 2006 04:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:28 PM.