Search notes:

Excel Object Model - worksheet event: selectionChange

option explicit

sub main()

  ' VBIDE needs reference {0002E157-0000-0000-C000-000000000046} «Microsoft Visual Basic for Applications Extensibility» 
  '(the -vbe flag in runVBAFilesInOffice)

    dim codeMod  as VBIDE.codeModule
    dim codeLine as long


  ' Get code module for «active worksheet»
    set codeMod = activeWorkbook.VBProject.VBComponents(activeSheet.name).codeModule

    codeLine = codeMod.countOflines

    codeLine = codeLine + 1
    codeMod.insertLines codeLine, "private sub worksheet_selectionChange(byVal target as range)"

    codeLine = codeLine + 1
'   codeMod.insertLines codeLine, "  msgBox(""x"")"
    codeMod.insertLines codeLine, "  cells(2,1).value=""You clicked "" & target.address"

    codeLine = codeLine + 1
    codeMod.insertLines codeLine, "end sub"

    cells(1,1).value = "Try clicking into cells"

    activeWorkbook.saved = true

end sub
Github repository about-MS-Office-object-model, path: /Excel//Worksheet/_events/selectionChange.vb

See also

Worksheet events

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1745405519, '160.79.108.1', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Office/Excel/Object-Model/Worksheet/_events/selectionChange(68): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78