Select ... but don't scroll into view?

K

Klaus Linke

Is it possible to select something, but don't have Word automatically scroll
that something into view?

The best I came up with:
Dim oldRange As Range
Set oldRange = Selection.Range.Duplicate
ActiveDocument.Characters(1).Select ' select something else
ActiveWindow.ScrollIntoView obj:=oldRange ' bring the old selection back
into view

.... but that still moves the view a bit.

(Background: I'm writing a macro that helps users edit (specially formatted)
endnotes. The macro should work both when the endnote reference is selected,
or when the cursor already is in some endnote. In the latter case I would
like to select the endnote reference up in the text, but not have Word
scroll it into view)

Regards,
Klaus
 
J

Jean-Guy Marcil

Klaus Linke was telling us:
Klaus Linke nous racontait que :
Is it possible to select something, but don't have Word automatically
scroll that something into view?

The best I came up with:
Dim oldRange As Range
Set oldRange = Selection.Range.Duplicate
ActiveDocument.Characters(1).Select ' select something else
ActiveWindow.ScrollIntoView obj:=oldRange ' bring the old selection
back into view

... but that still moves the view a bit.

(Background: I'm writing a macro that helps users edit (specially
formatted) endnotes. The macro should work both when the endnote
reference is selected, or when the cursor already is in some endnote.
In the latter case I would like to select the endnote reference up in
the text, but not have Word scroll it into view)


If you want to modify TextA while the user has TextB selected, you do not
need to select TextA as long as you have a way of knowing what TextA is.
For example, your sample code:

Dim oldRange As Range
Set oldRange = Selection.Range.Duplicate
ActiveDocument.Characters(1).Select ' select something else
ActiveWindow.ScrollIntoView obj:=oldRange ' bring the old selection back

could be:

Dim oldRange As Range
Dim RefRange As Range
Set oldRange = Selection.Range.Duplicate
Set RefRange = ActiveDocument.Characters(1)
With RefRange
.Font.Bold = True
End With
'Etc.

--

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

Klaus Linke

Hi Jean-Guy,

Thank you, I might have to resort to that. I would have liked to select the
endnote reference, mostly as a visual indicator for the user about the
endnote that is currently handled by my macro.
But it is too annoying if that causes the screen to scroll.
As another work-around, I may try to appy a highlight to the endnote
reference while my macro operates on the endnote, and remove the highlight
when it finishes.

Regards,
Klaus
 

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