AFAIK the only difference is one use ( ) and the other doesn't.
Joanne - 01 Mar 2005 20:03 GMT
I'm assuming that I wasn't too clear in my original message. I am debugging
some code that someone else wrote. In some areas of the code she used the ()
with .execute and in some areas she didn't. If I remove the (), I get an
error but I'm not sure why. I don't understand if there is a functional
difference in using parentheses or not since the rest of the .Execute
statement is the same.
> AFAIK the only difference is one use ( ) and the other doesn't.
> Could someone clarify what the difference is between
> .Execute (Replace:=wdReplaceall)
[quoted text clipped - 4 lines]
>
> Thank you very much.
It is *not* a stupid question. It's a consequence of a stupid design
decision by the programmers who created VB and VBA.
The article at http://word.mvps.org/faqs/macrosvba/BracketsWithArgmnts.htm
explains when to use or not use parentheses for functions and subroutines in
general. In the specific case you're asking about, .Execute can be used as
*either* a function (it returns a Boolean true/false value saying whether or
not it found the search text) *or* a subroutine (you don't want the value,
you just want to search).
When you assign the result to a variable
bFound = .Execute(Replace:=wdReplaceall)
or when you use the implied result as a condition in an If statement
If .Execute(Replace:=wdReplaceall) Then
you use the parentheses. When you just fire off the search, you don't.
The stupid part is that the VBA interpreter can tell whether you're using
the result or not, because it complains when you do it wrong -- so why
should it care?? Just do it...

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Greg - 01 Mar 2005 20:07 GMT
Thanks Jay. Goes to show how much I don't know and how much you have
to share.
Joanne - 01 Mar 2005 20:13 GMT
Thank you so much. That's the second time you've really clarified something
for me. I really appreciate it.
> > Could someone clarify what the difference is between
> > .Execute (Replace:=wdReplaceall)
[quoted text clipped - 28 lines]
> the result or not, because it complains when you do it wrong -- so why
> should it care?? Just do it...
use the parentheses when the execute is within an expression.

Signature
http://www.standards.com/; See Howard Kaikow's web site.
> Could someone clarify what the difference is between
> .Execute (Replace:=wdReplaceall)
[quoted text clipped - 4 lines]
>
> Thank you very much.