1.Excel
VBA点击单元格时执行事件!
Private Sub Worksheet_SelectionChange(ByVal Target As
Range)
If Target.Column = 1 And Target.Count = 1
Then
MsgBox "你选中了:" &
Target.Text
End If
End
Sub
2.在excel中,要实现光标离开单元格触发一个事件
Dim address As String
Private Sub Worksheet_SelectionChange(ByVal Target
As Range)
MsgBox "光标离开了 " & address & ",移动到了 " &
Target.address
address = Target.address
End Sub
3.excel vb中读取单元格的位置信息
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
MsgBox "显示列数" & Target.Column
MsgBox "显示行数" & Target.Row
MsgBox "显示当前工作薄的名字" & ActiveWorkbook.Name
MsgBox "显示当前工作表的名字" & Sh.Name
End Sub
例子:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim column As
String
Dim line As String
Dim value As String
column =
Target.column
line = Target.Row
value = Target.value
MsgBox "位置:" & line & "," & column & ",value:" &
value
MsgBox value = "AA"
MsgBox value = ""
End Sub
时间: 2024-10-26 08:07:10