De-Selecting Text

S

Susan

I have a macro that selects the whole text of a small document and then
copies it into another larger document. But when I'm done, the small
document remains selected (black with white text).
How do I "un-select" this text so that the document looks the same as before
the copy?

Thanks
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Susan > écrivait :
In this message said:
I have a macro that selects the whole text of a small document and then
copies it into another larger document. But when I'm done, the small
document remains selected (black with white text).
How do I "un-select" this text so that the document looks the same as before
the copy?

'_______________________________________
Dim StartRange As Range
'At beginning, save user selction:

Set StartRange = Selection.Range

'do your stuff
'Select doc, copy, paste, etc.

'and at the end of the macro
'Reset the selection to what it was:

StartRange.Select
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Susan

Thank you, Jezebel, but that method makes the cursor go to the beginning of
the document, then I have to find my place again.

Jean-Guy, that's exactly what I was looking for. But I'd like to understand
what is happening. I'm a newbie and not real familiar with how these things
work. I just plug in patches of code and fiddle until they do what I want
(or until I give up).

Am I setting the variable StartRange to the value of the document when
nothing is selected? And then when I reset the doc to the value of
StartRange, it goes back to the condition of nothing being selected?
(Pretty slick......)

Where can I find out more about writing code online?
Is there a beginner's primer somewhere?
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Susan > écrivait :
In this message said:
Thank you, Jezebel, but that method makes the cursor go to the beginning of
the document, then I have to find my place again.

Jean-Guy, that's exactly what I was looking for. But I'd like to understand
what is happening. I'm a newbie and not real familiar with how these things
work. I just plug in patches of code and fiddle until they do what I want
(or until I give up).

Am I setting the variable StartRange to the value of the document when
nothing is selected? And then when I reset the doc to the value of
StartRange, it goes back to the condition of nothing being selected?
(Pretty slick......)

Yes, if the cursor was an insertion point, and not a selection. If the user
had something selected before running your code, it will stay selected when
he regains control after the macros has run. Unless the content of the
document has changed...
Where can I find out more about writing code online?
Is there a beginner's primer somewhere?

Check out the Word MVP site:
http://www.word.mvps.org
You may also want to check out those technical articles:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/odc_ancword.asp
(Beware of the wrapped URL)
Googling very often yields what one needs if key words are chosen with care,
for example, to look for VBA threads:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&c2coff=1&group=microsoft.public.word.vba
And the Word MVP link page will provide you with hours of fun and
enlightenment!
http://word.mvps.org/UsefulLinks/index.htm

HTH
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top