+ Reply to Thread
Results 1 to 7 of 7

Keyboard/Mouse click event

  1. #1
    Registered User
    Join Date
    12-29-2004
    Posts
    12

    Question Keyboard/Mouse click event

    Can I write an event/procedure so that when user hits a key on keyboard or clicks any mouse key a message is displayed?

    Thanks.

    ~BS

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hi,

    You could. Is there some reason you can't write code for the form's mouse-up mouse-down and keypress procedures?

    Leith Ross

  3. #3
    Registered User
    Join Date
    12-29-2004
    Posts
    12
    I am new to VBA, so dont have much experience with mouse click events... would appreciate if you can give some example for mouse click events and where to place them.

    Thanks.

    Bhavesh

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Bahvesh,

    VBA is an event driven language. All objects have properties, methods, and events. Keyboard input and mouse movement are two very common system events. VBA Edit controls like TextBox, ComboBox, and ListBox respond to both. However, Static controls like a Label only respond to Mouse Events.

    It would help me to help you if you gave me an outline of what you want to accomplish. Once I understand what you want to do, I can show you examples of code to solve your problem. Think it over and re-post your programming objectives.

    Thanks,
    Leith Ross

  5. #5
    Registered User
    Join Date
    12-29-2004
    Posts
    12

    Question

    Hello Leith,

    I am using the following on many of my worksheets to enable/disable copy paste.
    http://xcelfiles.homestead.com/VBA_Quick13.html
    The problem with this code is that, when I open two workbooks simultaneously, with cut/copy disabled on both using worksheet_open, and then close one of the workbook (here I reset cut/copy and enable it again in workbook_beforeclose event), then it enables it on other workbook also.

    By using mouse click event, i want to run the disable macro again so that cut/copy remains disabled on other worksheet even if one worksheet is closed.

    Another option would be to figure out a way to disable cut/copy only on a particular worksheet, instead of disabling it for excel. In this code, if a worksheet is opened with cut/copy disabled, it disables it for excel as whole and does not allow cut/copy on a blank new worksheet also.

    I hope I was able to convey the problem.

    Thanks.

    Bhavesh

  6. #6
    Registered User
    Join Date
    01-09-2005
    Location
    London, UK
    Posts
    47
    Try running the script on Workbook_Activate / Workbook_Deactivate instead of Open/BeforeClose.

    That should serve your purposes.

  7. #7
    Registered User
    Join Date
    12-29-2004
    Posts
    12

    Thumbs up

    It works. Don't know why I did not try this earlier.

    Thanks.

    Bhavesh

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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