Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox "您选中的是第" & TargetRow & "行"
End Sub
Sub
CheckSelction()
With
Selection
If
Type
=
wdSelectionIP
Then
If
Start
=
0
Then
MsgBox
"光标位于文档首"
ElseIf
Start
=
ActiveDocumentContentEnd
-
1
Then
MsgBox
"光标位于文档末"
ElseIf
Characters
(1)
=
Chr(13)
Then
MsgBox
"光标位于段尾"
ElseIf
Start
=
Paragraphs(1)RangeStart
Then
MsgBox
"光标位于段首"
ElseIf
Information(wdFirstCharacterColumnNumber)
=
1
Then
MsgBox
"光标位于
行首
"
ElseIf
Characters(1)Information(wdFirstCharacterColumnNumber)
=
1
Then
MsgBox
"光标位于行末"
Else
MsgBox
"光标位段落中"
End
If
End
If
End
With
End
Sub
晕,不知道你解决了没有,看一下下面
代码
,你应该能举一反三。
If
ActiveDocumentRangeEnd
=
SelectionStart
+
1
Then
MsgBox
"页尾"
Else
MsgBox
Selectionend
+
1
'当前位置
End
If
Selection的end
和start
视需要而定,折叠状态下是一样的。
代码如下,请参考:
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 '指定鼠标使用绝对坐标系,此时,屏幕在水平和垂直方向上均匀分割成65535×65535个单元
Private Const MOUSEEVENTF_MOVE = &H1 '移动鼠标
Private Const MOUSEEVENTF_LEFTDOWN = &H2 '模拟鼠标左键按下
Private Const MOUSEEVENTF_LEFTUP = &H4 '模拟鼠标左键抬起
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Declare Function GetSystemMetrics32 Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long '获取分辨率
Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Screen_Click(ByVal X As Long, ByVal Y As Long) '移动并点击
mw = X / GetSystemMetrics32(0) 65535
mh = Y / GetSystemMetrics32(1) 65535
mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, mw, mh, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Public Function getmouse_x_y() As POINTAPI '坐标
GetCursorPos getmouse_x_y
End Function
Sub DisplayMonitorInfo()
Dim X As Long, Y As Long
X = GetSystemMetrics32(0) ' 宽度(像素)
Y = GetSystemMetrics32(1) ' 高度(像素)
MsgBox "屏幕分辨率为:" & X & " × " & Y & " 像素"
End Sub
Sub GetPosition() '获得坐标
DebugPrint getmouse_x_yX, getmouse_x_yY
[D2] = getmouse_x_yX
[D3] = getmouse_x_yY
End Sub
Sub test()
Screen_Click [D2], [D3]
End Sub
以上就是关于VBA,电子表格如何取光标所在的行号全部的内容,包括:VBA,电子表格如何取光标所在的行号、如何用VBA判断光标是不是在一段的结尾、在Word中,如何用VBA判断当前编辑光标的位置等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)