Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Mouse position within worksheet
Some years ago I remember reading an approach for determining the
mouse position within a sheet. I believe this used the GetCursorPos API to find the "absolute" mouse position relative to the window, then inserted a dummy chart object in cell A1, set a handle to this and then compared the coordinates of the chart to the mouse position to determine its relative position on the sheet. I've spent about an hour now searching for this code without success - does anyone have a copy they could re-post? Thanks a lot, Andrew |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Mouse position within worksheet
That approach doesn't work in 2007+ as embedded charts are not windows in
they way they were in previous versions. There are other ways of relating mouse coordinates to a cell address, or a cell position to screen coordinates depending on the overall objective. Regards, Peter T "Andrew" wrote in message ... Some years ago I remember reading an approach for determining the mouse position within a sheet. I believe this used the GetCursorPos API to find the "absolute" mouse position relative to the window, then inserted a dummy chart object in cell A1, set a handle to this and then compared the coordinates of the chart to the mouse position to determine its relative position on the sheet. I've spent about an hour now searching for this code without success - does anyone have a copy they could re-post? Thanks a lot, Andrew |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Mouse position within worksheet
Hi Peter,
Thanks for for the reply. I have a series of buttons displayed on the Ribbon which should insert a picture at a location selected by the user (by clicking on the worksheet). I need to be able to translate the mouse location to the appropriate sheet coordinates in order to insert the picture at the right spot. Thanks again, Andrew On 8 Feb, 15:21, "Peter T" <peter_t@discussions wrote: That approach doesn't work in 2007+ as embedded charts are not windows in they way they were in previous versions. There are other ways of relating mouse coordinates to a cell address, or a cell position to screen coordinates depending on the overall objective. Regards, Peter T "Andrew" wrote in message ... Some years ago I remember reading an approach for determining the mouse position within a sheet. *I believe this used the GetCursorPos API to find the "absolute" mouse position relative to the window, then inserted a dummy chart object in cell A1, set a handle to this and then compared the coordinates of the chart to the mouse position to determine its relative position on the sheet. *I've spent about an hour now searching for this code without success - does anyone have a copy they could re-post? Thanks a lot, Andrew- Hide quoted text - - Show quoted text - |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Mouse position within worksheet
Either I'm missing something or you've already got the information you need.
You say user clicks on the worksheet so presumably that activates a cell - what more do you need than that. IOW why do you need the mouse coordinates when you've already got the cell coordinates, which is what you will be using to position your inserted shape. Or, wondering, do you want the exact spot within some cell rather than say the top/left cell coordinate. Regards, Peter T "Andrew" wrote in message ... Hi Peter, Thanks for for the reply. I have a series of buttons displayed on the Ribbon which should insert a picture at a location selected by the user (by clicking on the worksheet). I need to be able to translate the mouse location to the appropriate sheet coordinates in order to insert the picture at the right spot. Thanks again, Andrew On 8 Feb, 15:21, "Peter T" <peter_t@discussions wrote: That approach doesn't work in 2007+ as embedded charts are not windows in they way they were in previous versions. There are other ways of relating mouse coordinates to a cell address, or a cell position to screen coordinates depending on the overall objective. Regards, Peter T "Andrew" wrote in message ... Some years ago I remember reading an approach for determining the mouse position within a sheet. I believe this used the GetCursorPos API to find the "absolute" mouse position relative to the window, then inserted a dummy chart object in cell A1, set a handle to this and then compared the coordinates of the chart to the mouse position to determine its relative position on the sheet. I've spent about an hour now searching for this code without success - does anyone have a copy they could re-post? Thanks a lot, Andrew- Hide quoted text - - Show quoted text - |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Mouse position within worksheet
Indeed - if I use the selected cell coordinates the inserted picture/
shape can be almost as much as the width of the cell away from the point where the user really wanted the insert to occur. It's not the end of the world but does appear a bit "budget". Thanks On 8 Feb, 16:05, "Peter T" <peter_t@discussions wrote: Either I'm missing something or you've already got the information you need. You say user clicks on the worksheet so presumably that activates a cell - what more do you need than that. IOW why do you need the mouse coordinates when you've already got the cell coordinates, which is what you will be using to position your inserted shape. Or, wondering, do you want the exact spot within some cell rather than say the top/left cell coordinate. Regards, Peter T "Andrew" wrote in message ... Hi Peter, Thanks for for the reply. I have a series of buttons displayed on the Ribbon which should insert a picture at a location selected by the user (by clicking on the worksheet). *I need to be able to translate the mouse location to the appropriate sheet coordinates in order to insert the picture at the right spot. Thanks again, Andrew On 8 Feb, 15:21, "Peter T" <peter_t@discussions wrote: That approach doesn't work in 2007+ as embedded charts are not windows in they way they were in previous versions. There are other ways of relating mouse coordinates to a cell address, or a cell position to screen coordinates depending on the overall objective. Regards, Peter T "Andrew" wrote in message .... Some years ago I remember reading an approach for determining the mouse position within a sheet. I believe this used the GetCursorPos API to find the "absolute" mouse position relative to the window, then inserted a dummy chart object in cell A1, set a handle to this and then compared the coordinates of the chart to the mouse position to determine its relative position on the sheet. I've spent about an hour now searching for this code without success - does anyone have a copy they could re-post? Thanks a lot, Andrew- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Mouse position within worksheet
Well, we wouldn't want anything remotely "budget" in Excel would we!
You can get the relative screen position of any cell with PointsToScreenPixelsX & 'Y. Apart from the mouse coordinates, which I assume you already know how to get, you'll need to factor in 'points-per-pixel' (typically 0.75) and Zoom. It gets a bit more complicated if there are multiple panes (freeze panes) but PointsToScreenPixelsX/Y now works with the 'Pane' object, assuming you know which pane you'll be dealing with, if applicable. Only other thing you need to figure for your needs is how to trap the mouse click. Easiest would be in the selection event, which might mean you need to use WithEvents to trap the sheet events (unless of course your app is only geared to work in a given workbook). Regards, Peter T "Andrew" wrote in message ... Indeed - if I use the selected cell coordinates the inserted picture/ shape can be almost as much as the width of the cell away from the point where the user really wanted the insert to occur. It's not the end of the world but does appear a bit "budget". Thanks On 8 Feb, 16:05, "Peter T" <peter_t@discussions wrote: Either I'm missing something or you've already got the information you need. You say user clicks on the worksheet so presumably that activates a cell - what more do you need than that. IOW why do you need the mouse coordinates when you've already got the cell coordinates, which is what you will be using to position your inserted shape. Or, wondering, do you want the exact spot within some cell rather than say the top/left cell coordinate. Regards, Peter T "Andrew" wrote in message ... Hi Peter, Thanks for for the reply. I have a series of buttons displayed on the Ribbon which should insert a picture at a location selected by the user (by clicking on the worksheet). I need to be able to translate the mouse location to the appropriate sheet coordinates in order to insert the picture at the right spot. Thanks again, Andrew On 8 Feb, 15:21, "Peter T" <peter_t@discussions wrote: That approach doesn't work in 2007+ as embedded charts are not windows in they way they were in previous versions. There are other ways of relating mouse coordinates to a cell address, or a cell position to screen coordinates depending on the overall objective. Regards, Peter T "Andrew" wrote in message ... Some years ago I remember reading an approach for determining the mouse position within a sheet. I believe this used the GetCursorPos API to find the "absolute" mouse position relative to the window, then inserted a dummy chart object in cell A1, set a handle to this and then compared the coordinates of the chart to the mouse position to determine its relative position on the sheet. I've spent about an hour now searching for this code without success - does anyone have a copy they could re-post? Thanks a lot, Andrew- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to get position of mouse via VB in a worksheet | Excel Programming | |||
Mouse Position | Excel Programming | |||
Position of the mouse pointer | Excel Programming | |||
Mouse Position | Excel Programming | |||
position mouse cursor in msg box | Excel Programming |