Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Left and Right Mouse Click Event

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Last edited by DocAElstein; 10-26-2023 at 12:23 PM.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Yes you can using

    Code:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        
        Cancel = True
        MsgBox "Double-Clicked"
        
    End Sub
    OR
    Code:
    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    
        Cancel = True
        MsgBox "Right-Clicked"
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Hallo
    Let's analyze:

    Code:
    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    
        Cancel = True
        MsgBox "Right-Clicked"
        
    End Sub
    In a paper without a password by running the code occur at least two possibilities.
    Example: I make right click on a cell and activate the macro, but if I were on an image this command does not work.
    You can disable the selection image forever without protect the sheet?

  4. #4
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0
    Quote Originally Posted by Excel Fox View Post
    Yes you can using

    Code:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        
        Cancel = True
        MsgBox "Double-Clicked"
        
    End Sub
    OR
    Code:
    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    
        Cancel = True
        MsgBox "Right-Clicked"
        
    End Sub


    beg pardon, 1 year later , am looking for the left click version for events. this would be for a mouse left click only, so can tab into cell without the event taking place. thanks.
    Last edited by EQX; 11-24-2012 at 04:59 AM.

  5. #5
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    To disable the selection of image, you will have to protect the sheet. If you want users to be able to edit the cells, you can unlock the cells, and then protect the sheet.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  6. #6
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Hallo

    This is an example of code to enable I can not enter password

    Code:
    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
        Cancel = True
        Application.CommandBars.FindControl(ID:=130).Execute
    end sub
    I would like to draw a line on the sheet and images

  7. #7
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    You can protect the sheet through code and then allow to draw a line through code. To do this, protect the sheet(s) by

    Code:
    Sheet1.Protect UserInterfaceOnly:=True, Password:="xyz"
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  8. #8
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Meanwhile, thank you for the answers, but if I run RightClick on protected sheet over an image the event does not Run.
    Here we are again as the first

  9. #9
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Why do you want to right-click? You can use a normal click, and the assigned macro will run even if the sheet is protected. And if you want the shapes also to be unprotected, then use

    Code:
    Sheet1.Protect UserInterfaceOnly:=True, Password:="xyz", DrawingObjects:=False
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  10. #10
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Hallo
    Still to solve the problems of selection wonder how the subject should be written the following code:
    Code:
    Sub Test()
        ActiveSheet.Shapes("Picture 309").Select        'I select the object
        ActiveSheet.Shapes("Picture 309").Deselect      'Here I would like to deselect the object
    End Sub
    Obviously, the code does not work ...

Similar Threads

  1. Set Adjust A Button Top Left Position Programmatically
    By jeffrey159 in forum Access Help
    Replies: 5
    Last Post: 02-02-2013, 06:24 PM
  2. Sort data sheet by right_click of mouse
    By Rasm in forum Excel and VBA Tips and Tricks
    Replies: 3
    Last Post: 12-08-2012, 07:34 PM
  3. Replies: 2
    Last Post: 02-29-2012, 08:24 PM
  4. Replies: 3
    Last Post: 12-07-2011, 09:59 PM
  5. Replies: 2
    Last Post: 11-08-2011, 08:52 AM

Posting Permissions

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