Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Execute Method of Find Object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joanne - 01 Mar 2005 19:03 GMT
Could someone clarify what the difference is between
.Execute (Replace:=wdReplaceall)
and
.Execute Replace:=wdReplaceall
with the "Find" object.  I know this is a stupid question but I'm not sure
when to use the () and when not to.

Thank you very much.
Greg - 01 Mar 2005 19:33 GMT
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.
Jay Freedman - 01 Mar 2005 20:02 GMT
> 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...
Howard Kaikow - 01 Mar 2005 21:59 GMT
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.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.