Well, this intrigued me, so I gave it a go at giving some kind of proof-of-concept as a brain teaser. This is by no means any sort of polished product, and I may be unable to take it much further, but this uses the WinAPI call to find out your cursor position, and then uses a combination of a modeless form and the Application.OnTime functionality.
Everything is default- so it's called CommandButton1, UserForm1, Module1, etc. There is no error trapping. But if you can try to incorporate from here, please let us know what you discover.
In the ThisDocument module:
[vba]
Option Explicit
Private Sub CommandButton1_Click()
Unload UserForm1
MsgBox "run me"
End Sub
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal x As Single, _
ByVal y As Single)
Dim lCurX As Long
Dim lCurY As Long
GetCursorPosition lCurX, lCurY
ShowMe lCurX, lCurY
End Sub
[/vba]
In the UserForm1 module
NOTE: this userform needs to have ShowModal set to FALSE
[vba]
Option Explicit
Private Sub UserForm_Activate()
'start a timer of 5 seconds for the form to be dismissed, if no input
Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="DismissMe"
End Sub
Private Sub UserForm_Initialize()
bShowing = True
End Sub
Private Sub UserForm_Terminate()
bShowing = False
End Sub
[/vba]
In the Module1 module:
[vba]
Option Explicit
Public bShowing As Boolean
'Info about this at:
http://support.microsoft.com/kb/152969
' Access the GetCursorPos function in user32.dll
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
' GetCursorPos requires a variable declared as a custom data type
' that will hold two integers, one for x value and one for y value
Type POINTAPI
X_Pos As Long
Y_Pos As Long
End Type
Sub GetCursorPosition(x As Long, y As Long)
Dim Hold As POINTAPI
'use the API to return our public type
GetCursorPos Hold
'return them back outside the sub as the passed in parameters
x = Hold.X_Pos
y = Hold.Y_Pos
End Sub
Public Sub ShowMe(lWhereX As Long, lWhereY As Long)
If bShowing = False Then
bShowing = True
UserForm1.Show
End If
UserForm1.Top = lWhereY
UserForm1.Left = lWhereX
End Sub
Public Sub DismissMe()
Unload UserForm1
bShowing = False
End Sub
[/vba]
This is almost embarrassingly unpolished code, but I used this as more of an escape from my real work, so apologies for not giving more explanation. Perhaps this can give someone else an idea of how to give you a more polished end-product.