VBA - CopyPasteCode 与 Sendkeys
VBA - CopyPasteCode with Sendkeys
我在 excel 工作簿中使用 IDE 并尝试执行以下代码。
Sub cpypaste()
Range("E7").Select
SendKeys ("^c"), True
Application.Wait (Now + TimeValue("00:00:01"))
Range("G7").Select
SendKeys ("^v"), True
End Sub
并不是说我不知道其他方法,只是好奇为什么这不起作用。我也用键盘快捷键和 cmdbutton 尝试了 运行 这段代码。
任何帮助将不胜感激。
使用 sendKeys 充其量只是粪便。我假设您是从代码 window 开始编写代码的,因此,命令试图引用 window。 Excel 需要激活才能接收命令。
Sub cpypaste()
AppActivate Application.Caption 'Activates the window.
Range("E7").Select
SendKeys String:="^c", Wait:=True
Application.Wait (Now + TimeValue("00:00:01"))' this line I belive is not needed, with the wait as true.
Range("G7").Select
SendKeys String:="^v", Wait:=True
End Sub
我在 excel 工作簿中使用 IDE 并尝试执行以下代码。
Sub cpypaste()
Range("E7").Select
SendKeys ("^c"), True
Application.Wait (Now + TimeValue("00:00:01"))
Range("G7").Select
SendKeys ("^v"), True
End Sub
并不是说我不知道其他方法,只是好奇为什么这不起作用。我也用键盘快捷键和 cmdbutton 尝试了 运行 这段代码。 任何帮助将不胜感激。
使用 sendKeys 充其量只是粪便。我假设您是从代码 window 开始编写代码的,因此,命令试图引用 window。 Excel 需要激活才能接收命令。
Sub cpypaste()
AppActivate Application.Caption 'Activates the window.
Range("E7").Select
SendKeys String:="^c", Wait:=True
Application.Wait (Now + TimeValue("00:00:01"))' this line I belive is not needed, with the wait as true.
Range("G7").Select
SendKeys String:="^v", Wait:=True
End Sub