【问题标题】:VBA - CopyPasteCode with SendkeysVBA - 使用 Sendkeys 复制粘贴代码
【发布时间】:2015-10-21 18:41:46
【问题描述】:

我在 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 运行此代码。 任何帮助将不胜感激。

【问题讨论】:

  • 代码对我有用,....
  • 我可以在我的 excel 应用程序中修改以使其工作的任何设置。您使用的是哪个 excel 版本?
  • xl'10... 我刚刚复制了您的代码,粘贴到模块中并单击运行。
  • xl2007 上没有.. :(
  • 怎么不工作了?有什么错误吗?

标签: excel sendkeys vba


【解决方案1】:

使用 sendKeys 充其量只是粪便。我假设您是从代码窗口启动代码,因此,命令试图引用该窗口。需要激活 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多