When i call GetCaretPos in MS Word Addin, It always return's a same value.
When i Enable IME,it can return the correct value. Some one can tell me why?

RE: GetCaretPos can't get the correct value by JeanGuyMarcil

JeanGuyMarcil
Tue Jul 15 05:01:00 PDT 2008

"wak" wrote:

> When i call GetCaretPos in MS Word Addin, It always return's a same value.
> When i Enable IME,it can return the correct value. Some one can tell me why?

What is "GetCaretPos?"

Many methods that work with the selection object will not work correctly (or
not at all) if the active window is not visible.

RE: GetCaretPos can't get the correct value by wak

wak
Tue Jul 15 05:06:00 PDT 2008



"Jean-Guy Marcil" wrote:

> "wak" wrote:
>
> > When i call GetCaretPos in MS Word Addin, It always return's a same value.
> > When i Enable IME,it can return the correct value. Some one can tell me why?
>
> What is "GetCaretPos?"
>
> Many methods that work with the selection object will not work correctly (or
> not at all) if the active window is not visible.

GetCaretPos is Win32Api, I think i can use API to do some tasks instead VBA.
I want to get the current caret postion.

Re: GetCaretPos can't get the correct value by Helmut

Helmut
Tue Jul 15 07:47:53 PDT 2008

Hi,

at work, with Office 2002 and Windows XP
I see the same behaviour as you do.

However, at home, with Vista Small Business
and Office XP, the following code is working:

Option Explicit
' ---------------------------------------------
Public Declare Function GetCaretPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Type POINTAPI ' 8 Bytes
x As Long
y As Long
End Type

Public Sub WhereAmI()
Dim p As POINTAPI
Dim l As Long
l = GetCaretPos(p)
ActiveDocument.Range.InsertAfter _
"(" & p.x & "," & p.y & ")"
MyStart
End Sub

Sub MyStart() ' for ongoing evaluation of caret position
Application.OnTime _
When:=Now + TimeValue("00:00:03"), _
name:="WhereamI"
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: GetCaretPos can't get the correct value by wak

wak
Tue Jul 15 08:10:02 PDT 2008



"Helmut Weber" wrote:

> Hi,
>
> at work, with Office 2002 and Windows XP
> I see the same behaviour as you do.
>
> However, at home, with Vista Small Business
> and Office XP, the following code is working:
>
> Option Explicit
> ' ---------------------------------------------
> Public Declare Function GetCaretPos Lib "user32" _
> (lpPoint As POINTAPI) As Long
>
> Private Type POINTAPI ' 8 Bytes
> x As Long
> y As Long
> End Type
>
> Public Sub WhereAmI()
> Dim p As POINTAPI
> Dim l As Long
> l = GetCaretPos(p)
> ActiveDocument.Range.InsertAfter _
> "(" & p.x & "," & p.y & ")"
> MyStart
> End Sub
>
> Sub MyStart() ' for ongoing evaluation of caret position
> Application.OnTime _
> When:=Now + TimeValue("00:00:03"), _
> name:="WhereamI"
> End Sub
>
> --
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Vista Small Business, Office XP
>

Thanks for your code, it realy work.
but I want to know a common way to get
the caret pos of all versions of word,
and outlook have the same problem,
(GetCaretPos works ok in powerpoint).
Microsoft knows the caret pos, so i believe
there is a way to get it correct, any idea?