Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preserving select.find

Status
Not open for further replies.

PinkeyNBrain

IS-IT--Management
Dec 12, 2006
279
US
Please consider the following pseudo code:
Code:
With Selection.Find
   .Text = "foo"
End With
If Selection.Find.Execute Then
   preserved_selection_state = Selection.Find
   Call some_subroutine_that_modifies_Selection
   Selection.Find = preserved_selection_state
End If
Can something like this be done? The actual code leading up to ths is somewhat more complicated, so the pseudo code is being submitted to get my idea / need across.
 

Yes and no!

You shouldn't be using the Selection, and you shouldn't normally be modifying it. Use Range objects instead, and use different ones in your two routines. It's hard to be more specific without more detail.


Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Thanks for the tip. Most of what I know about VB programing is through generating macros and disecting them. C++, perl, SQL, not a problem. VB seems to have it's own rules sometimes. I'll look into Range objects.
 

VBA - itself - isn't difficult. It's the Object Models of the parent applications that are harder to get to grips with.

In the case of Word, the Selection is what the user sees - when you change it you change what the user sees. Although you can, for the most part, suppress the screen flashing associated with this, you are still interfering in user space.

When working in code, Range objects are, by and large, the same type of thing as the selection but you can have as many as you want representing different parts of the document and they belong to the code not the user.


Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top