ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Capture mouses X &Y position on a worksheet (https://www.excelbanter.com/excel-programming/297496-capture-mouses-x-y-position-worksheet.html)

Stewart[_3_]

Capture mouses X &Y position on a worksheet
 
Capture mouses X&Y position on a worksheet. I want to use
the before right click option of the worksheet to display
a custom toolbar. I want to use the current position of
the mouse to set the left and top parameters for the
toolbar.

Is there a better way?

Jake Marx[_3_]

Capture mouses X &Y position on a worksheet
 
Hi Stewart,

Are you trying to show a popup menu that you've created? If so, you don't
need to know the coordinates; you can use the ShowPopup method without any
arguments to show the menu.

Here's some (very ugly) code that gives you a quick overview of how you
could accomplish this. Typically, you'd want to create your menu upon
workbook open, pop it up as needed, and destroy it at workbook close.

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
On Error Resume Next
Application.CommandBars("jake").Delete
On Error GoTo 0

With Application.CommandBars.Add("jake", msoBarPopup, , True)
With .Controls.Add(msoControlPopup)
.Caption = "&Edit"
With .Controls.Add(msoControlButton)
.Caption = "&Copy"
End With
With .Controls.Add(msoControlButton)
.Caption = "&Paste"
End With
End With
.ShowPopup
End With

Cancel = True
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Stewart wrote:
Capture mouses X&Y position on a worksheet. I want to use
the before right click option of the worksheet to display
a custom toolbar. I want to use the current position of
the mouse to set the left and top parameters for the
toolbar.

Is there a better way?



No Name

Capture mouses X &Y position on a worksheet
 
Got it - thanks!
-----Original Message-----
Hi Stewart,

Are you trying to show a popup menu that you've created?

If so, you don't
need to know the coordinates; you can use the ShowPopup

method without any
arguments to show the menu.

Here's some (very ugly) code that gives you a quick

overview of how you
could accomplish this. Typically, you'd want to create

your menu upon
workbook open, pop it up as needed, and destroy it at

workbook close.

Private Sub Worksheet_BeforeRightClick(ByVal Target As

Range, _
Cancel As Boolean)
On Error Resume Next
Application.CommandBars("jake").Delete
On Error GoTo 0

With Application.CommandBars.Add("jake",

msoBarPopup, , True)
With .Controls.Add(msoControlPopup)
.Caption = "&Edit"
With .Controls.Add(msoControlButton)
.Caption = "&Copy"
End With
With .Controls.Add(msoControlButton)
.Caption = "&Paste"
End With
End With
.ShowPopup
End With

Cancel = True
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address

unmonitored]


Stewart wrote:
Capture mouses X&Y position on a worksheet. I want to

use
the before right click option of the worksheet to

display
a custom toolbar. I want to use the current position of
the mouse to set the left and top parameters for the
toolbar.

Is there a better way?


.



All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com