在 Excel 工作表中,选择单元格 A1,然后使用组合键 Ctrl+Shift+End 将选择包含数据的工作表范围。使用 VBA 语句
Range("A1").Select
Sendkeys "^+{END}"
突出范围。但是,似乎无论如何都无法检索所选区域的地址。 VBA 似乎无法识别已选择的范围。 将不胜感激有关如何返回所选范围的建议。
最佳答案
我假设您知道您不需要使用 SendKeys 来模仿 Ctrl+Shift+End。
您可以使用 CurrentRegion 命令选择或确定范围的范围。
Sub test()
Range("A1").CurrentRegion.Select
' next you could do something with Selection.Address
' just for illustration, you don't need to select if your goal
' is to return the address of the range.
' here I'm using debug.print only to have a container for the
' returned range address without selecting the range first
Debug.Print Range("A1").CurrentRegion.Address
End Sub
关于excel - 使用 SendKeys 选择单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64418797/