excel - 使用 SendKeys 选择单元格

标签 excel vba range selection

在 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/

相关文章:

vba - 从收件箱中删除电子邮件,并通过规则->脚本将其从已删除项目文件夹中删除

range - 输入范围连接

vba - Excel VBA 发送到 MSXML2.XMLHTTP 不起作用

regex - 如何像在Excel中一样在Excel VBA中使用Excel Replace <*>? (常用表达)

excel - 检查 Excel 2003 数据验证

vba - Excel VBA - 第一行抛出 "Argument not optional"

javascript - document.createRange() 和 new Range() 有什么区别?

javascript - 在某个时间范围内有效的对象的搜索列表

vba - 删除和添加Excel表中的项目VBA

java - java 中 EXCEL 的平台独立连接字符串