+ Reply to Thread
Results 1 to 6 of 6

Making a macro more dynamic.

  1. #1
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    251

    Making a macro more dynamic.

    I wanted to create a "mouse over tool tip", which displays a userform when the mouse is hovering over a label on my worksheet, and then closes the userform when the mouse moves away.

    So far I have managed to achieve this using POINTAPI to create MouseX and MouseY functions to detect the location of the mouse with the "Label1_MouseMove" event.

    Please Login or Register  to view this content.
    My issue now is how do I a) make this same macro apply to all labels on the worksheet? And b) How can I get the screen coordinates for the location of the control?

    At present I have had to manually work out the location of the control. Using ".Top" and ".Left" only returns the position inside of the worksheet, not the location on the screen itself.

    If anyone has any ideas on either of these issues, it would be greatly appreciated!
    Last edited by PrizeGotti; 06-15-2022 at 10:24 AM.

  2. #2
    Forum Contributor GWteB's Avatar
    Join Date
    12-13-2021
    Location
    GMT +1
    MS-Off Ver
    2013
    Posts
    136

    Re: Making a macro more dynamic.

    Quote Originally Posted by PrizeGotti View Post
    My issue now is how do I a) make this same macro apply to all labels on the worksheet? And b) How can I get the screen coordinates for the location of the control?
    ad a):
    I think you actually don't want that, since you want a pop-up on hovering over a label, so any current pop-up (if any ...) needs to be hide first.
    ad b):
    Imo you don't need to if you introduce an extra (transparent) label in the background, of which its mouse move event handler takes care of hiding the pop-up.
    Did this help? Say thanks by clicking the ★

  3. #3
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    251

    Re: Making a macro more dynamic.

    Quote Originally Posted by GWteB View Post
    ad a):
    I think you actually don't want that, since you want a pop-up on hovering over a label, so any current pop-up (if any ...) needs to be hide first.
    ad b):
    Imo you don't need to if you introduce an extra (transparent) label in the background, of which its mouse move event handler takes care of hiding the pop-up.
    Sorry but I'm really confused by your answer. A) The pop up already closes once you stop hovering over the label. B) I need to know the location of the label control in regards to its positioning in the overall screen resolution.

    The macro already works, I'm just looking for a way to avoid having to write out the same macro for every label and have to manually calculate the location of the control which in itself will restrict its use to one resolution size.

  4. #4
    Forum Contributor GWteB's Avatar
    Join Date
    12-13-2021
    Location
    GMT +1
    MS-Off Ver
    2013
    Posts
    136

    Re: Making a macro more dynamic.

    Maybe I could have been more clear, I'll give it a try.

    The MouseMove event handler is executed when you hover the mouse over the label. You're wanting to use the exact screen coordinates to determine when the mouse is NOT hovering over a label. If you use an extra label that is the size of the UsedRange of your worksheet, the mouse will move over that label when it exits a pop-up label. Then you don't need the screen coordinates at all.
    Of course, the event handlers of all labels must, in addition to showing the pop-up, also make the extra label accessible to the mouse, while the event of that extra label then makes this same label inaccessible, so that the user can select worksheet ranges again.

    Since you don't need to know the screen location of each label, you can provide one macro which can be called from each mouse move event handler, except for the event handler of the extra label.


    EDIT: forgot to mention that with this approach a continue executing DoEvents loop isn't needed anymore...
    Last edited by GWteB; 06-13-2022 at 03:36 PM.

  5. #5
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    251

    Re: Making a macro more dynamic.

    Quote Originally Posted by GWteB View Post
    Maybe I could have been more clear, I'll give it a try.

    The MouseMove event handler is executed when you hover the mouse over the label. You're wanting to use the exact screen coordinates to determine when the mouse is NOT hovering over a label. If you use an extra label that is the size of the UsedRange of your worksheet, the mouse will move over that label when it exits a pop-up label. Then you don't need the screen coordinates at all.
    Of course, the event handlers of all labels must, in addition to showing the pop-up, also make the extra label accessible to the mouse, while the event of that extra label then makes this same label inaccessible, so that the user can select worksheet ranges again.

    Since you don't need to know the screen location of each label, you can provide one macro which can be called from each mouse move event handler, except for the event handler of the extra label.


    EDIT: forgot to mention that with this approach a continue executing DoEvents loop isn't needed anymore...
    Ah that makes a lot more sense, and is actually genius. Your help is much appreciated!

  6. #6
    Forum Contributor GWteB's Avatar
    Join Date
    12-13-2021
    Location
    GMT +1
    MS-Off Ver
    2013
    Posts
    136

    Re: Making a macro more dynamic.

    You are welcome and thanks for posting back.

    Note that it may be necessary for the MouseMove event handler to check beforehand whether the pop-up is already displayed in order to avoid screen flickering.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Making code dynamic
    By frankt68 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-27-2021, 05:09 AM
  2. Making sheet name dynamic
    By Rahul15292000 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-13-2019, 11:40 PM
  3. Making Dynamic Name Range more dynamic
    By dluhut in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-23-2019, 11:51 AM
  4. Making dynamic vlookup
    By Knarf6 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-02-2016, 10:30 AM
  5. making macro dynamic
    By rexer231 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-11-2013, 03:48 AM
  6. [SOLVED] Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I think.
    By ajava in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-07-2012, 02:48 PM
  7. Making print range dynamic in macro
    By Newbie dumbo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2005, 06:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1