Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    313

    Unanswered: How does the program detect the user's control

    Hi,

    In VBA,
    Can we detect whether or not the user click "Tab" key, or Arrow-keys, or mouse pointer to move/select the cell?

    Thanks.

  2. #2
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi accessman2

    I am not sure what you mean by "Tab" key, but I have assumed it is the sheet tabs ?

    To detect worksheet Tab Click (and Ctl+PageUp/Down) you can use the following events in the 'ThisWorkbook' module

    Code:
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
        MsgBox "Tab Clicked (Sheet changed TO " & Sh.Name & ")"
    End Sub
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
        MsgBox "Sheet changed  (" & Sh.Name & ")  Cell " & Target.Address
    End Sub
    
    Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
        MsgBox "Tab Clicked (Sheet changed FROM " & Sh.Name & ")"
    End Sub
    and to detect moving around a sheet (Curser keys, Tab key, move click) you can use the following events in the individual sheet module(s). ALso sheet changes
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        MsgBox "Changed"
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        MsgBox "Moved"
    End Sub
    Does that help ?

    MTB

Posting Permissions

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