relative position cursor

Ö

Örjan Skoglösa

Sorry if this has been discussed lately.

Is there a possibility to return the position of the selection
relative to the borders of the active window?

I have found RelativeToPage and RelativeToTextBoundary but I would
like to move the cursor to the midst of the shown area.

TIA
Örjan
 
W

Word Heretic

G'day Örjan Skoglösa <[email protected]>,

I am sorry, I don't understand. Are you wanting to get the absolute
screen co-ordinates for the cursor rather than the document position?

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Örjan Skoglösa reckoned:
 
Ö

Örjan Skoglösa

G'day Örjan Skoglösa <[email protected]>,

I am sorry, I don't understand. Are you wanting to get the absolute
screen co-ordinates for the cursor rather than the document position?
Hi Steve,

yes, quite so.

I (or rather a colleague of mine) want to move the cursor to the
center of the shown area.

quote start
In a Word macro, I would like to move the cursor to a vertical position
of
about 1/3 of the available window height. For instance, suppose the
document window has a height of 450 points, then I want the cursor to be
moved to about 150 points counted from the top of the window. I may be
overlooking something, but isn't there an easy, straightforward way to
test
for the vertical position of the cursor?
quote end

I thought I might help and started to play around, but could not find
any way.

TIA
Örjan

PS. Thanks also for the other answer.
 
K

Klaus Linke

Hi Örjan,

You could try to play with ActiveWindow.ScrollIntoView.

It's buggy though.

The help says that it has two parameters, Obj and Start (where Obj can be a
range, such as Selection.Range).

Start:=True should align the start of Obj at the top left of the window,
and Start:=False should align the end of the Obj at the bottom right of the
window.

If this would work, you could center the selection on screen, once you know
how many lines it has:
LinesInSelection =
Selection.Characters.Last.Information(wdFirstCharacterLineNumber) - _
Selection.Characters.First.Information(wdFirstCharacterLineNumber)
(using ActiveWindow.SmallScroll)

Unfortunately, it doesn't work as advertised.

But perhaps "ActiveWindow.ScrollIntoView Obj:=Selection.Range, Start:=True"
works for you, since it seems to center the selection on the screen, more
or less (contrary to the help file).

Regards,
Klaus
 
W

Word Heretic

G'day Örjan Skoglösa <[email protected]>,

<Mumbles something about having to use system routines that I know
nothing about unfortunately>

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Örjan Skoglösa reckoned:
 
Ö

Örjan Skoglösa

Hi Klaus,

Unfortunately I myself still use Word97 that does not have this
method, but I will forward it.

Thanks.

Örjan
 
W

Word Heretic

G'day Örjan Skoglösa <[email protected]>,

Public Sub ActiveWindowScrollIntoView(Obj As Range, Optional Start As
Boolean = True)
'www.wordheretic.com
'replacement for Win2k command Activewindow.scrollintoview for 97
users
'we ignore start - its just there, like the names of the parms, for
compat
'It shows the selection near the top of the screen

#If VBA6 Then

ActiveWindow.ScrollIntoView Obj, Start

#Else

'Set a custom bookmark name to use

Const TempBookmark As String = "Delete_Me_Heretic_UI_ScrollIntoView"

Obj.Select
ActiveDocument.Bookmarks.Add TempBookmark, Obj
Selection.GoTo wdGoToBookmark, , , TempBookmark
ActiveDocument.Bookmarks(TempBookmark).Delete

#End If
End Sub

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Örjan Skoglösa reckoned:
 
Ö

Örjan Skoglösa

Hi Steve,

Thanks for your reply.

Sadly, I´m not really able to follow your advice, probably because I
myself seldom use arguments.
I have tried to call your sub from another sub to feed it with the
required Obj, but without success.


BR,
Örjan
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Örjan Skoglösa > écrivait :
In this message, < Örjan Skoglösa > wrote:

|| Hi Steve,
||
|| Thanks for your reply.
||
|| Sadly, I´m not really able to follow your advice, probably because I
|| myself seldom use arguments.
|| I have tried to call your sub from another sub to feed it with the
|| required Obj, but without success.
||

Steve's code does work.
Are you using something like:
'_______________________________________
Sub Call_Steves_Code ()

Dim MyRange as Range

Set MyRange = Selection.Range
'Or any other range

ActiveWindowScrollIntoView MyRange, True

End Sub
'_______________________________________

When you say "without success", it does not help us to help you! Give us an
example, give more details... What is the expected behaviour when you run
the code and what is the actual result?

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

Örjan Skoglösa

Bonjour Jean-Guy,

I had wrongly enclosed the arguments in brackets in the calling
routine and therefore only got a error message.

Now Steve´s ScrollIntoView-Ersatz works very well.

I see forward to the possibility to position the cursor on the screen
with the help of a correctly functioning Start parameter the way Klaus
described.

Thanks a lot to all who helped.

BR,
Örjan
 

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