|
-
Nov 8th, 2016, 11:19 AM
#1
[vba] how to call event: show tooltip of footnote?
Hi,
I need to show tooltip of note programmatically.
(it'll be excellent, if it's been possible without delay). As you know, to show tooltip of note, you should move mouse pointer to note reference and wait ~ 1 sec.
I tried to imitate mouse move using SetCursorPos, but it work on MS Word 2003 only. On 2008 and newer it work not always. Also there is a delay.
Maybe, there is a way to call FootNote_MouseMouse Event directly?
Here is my try (code for ThisDocument module):
Code:
Option Explicit
Private WithEvents appWord As Word.Application
Private Type RANGE_POSITION
Left As Long
Top As Long
Width As Long
Height As Long
End Type
Private Enum DIRECTION
DIR_FORWARD
DIR_BACKWARD
End Enum
Private Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
Dim oKey1 As KeyBinding
Dim oKey2 As KeyBinding
Private Sub appWord_WindowActivate(ByVal Doc As Word.Document, ByVal Wn As Word.Window)
Call BindKey
End Sub
Private Sub Document_Close()
On Error Resume Next
oKey1.Clear
oKey2.Clear
End Sub
Private Sub Document_Open()
Set appWord = Word.Application
Call BindKey
End Sub
Private Sub BindKey()
With Application
'Goto Note by hotkey Alt + Ctrl + Num4 (or Num6)
.CustomizationContext = ThisDocument
Set oKey2 = .KeyBindings.Add( _
KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyControl, wdKeyNumeric4), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="GotoNoteBack")
Set oKey2 = .KeyBindings.Add( _
KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyControl, wdKeyNumeric6), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="GotoNoteNext")
End With
End Sub
Public Sub GotoNoteNext()
FindNote DIR_FORWARD
End Sub
Public Sub GotoNoteBack()
FindNote DIR_BACKWARD
End Sub
Private Sub FindNote(dir As DIRECTION)
Dim i As Long
If ActiveDocument.Footnotes.Count = 0 And ActiveDocument.Endnotes.Count = 0 Then
MsgBox "Document has no notes.", vbInformation
Exit Sub
End If
If ActiveDocument.Footnotes.Count > 0 Then
If dir = DIR_FORWARD Then
For i = 1 To ActiveDocument.Footnotes.Count
If CheckNote(ActiveDocument.Footnotes(i).Reference, dir) Then Exit Sub
Next
Else
For i = ActiveDocument.Footnotes.Count To 1 Step -1
If CheckNote(ActiveDocument.Footnotes(i).Reference, dir) Then Exit Sub
Next
End If
If MsgBox("Search has been completed. Start again?", vbYesNo) = vbYes Then
Selection.Start = IIf(dir = DIR_FORWARD, 0, ActiveDocument.Content.End)
FindNote dir
End If
End If
End Sub
Private Function CheckNote(RA As Range, dir As DIRECTION) As Boolean
Dim RP As RANGE_POSITION
Dim cX As Long, cY As Long
If IIf(dir = DIR_FORWARD, RA.Start > Selection.Start, RA.Start < Selection.Start) Then
Selection.Start = RA.Start
Selection.End = RA.Start
Selection.Range.Select
Call ActiveWindow.GetPoint(RP.Left, RP.Top, RP.Width, RP.Height, RA)
cX = RP.Left + RP.Width \ 2
cY = RP.Top + RP.Height \ 2
SetCursorPos cX, cY
CheckNote = True
End If
End Function
Searching of notes is on hotkeys: Ctrl + Alt + Num4 (Num6).
You should create several notes in document first.
Thank you in advance,
Alex.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|