Excel VBA-带Sendkeys的复制粘贴代码

Excel VBA-带Sendkeys的复制粘贴代码,excel,sendkeys,vba,Excel,Sendkeys,Vba,我正在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 并不是说我不知道其他的方法,只是好奇为什么

我正在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充其量只是一种排泄物。我假设您是从代码窗口启动代码,因此,命令试图引用该窗口。需要激活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应用程序中修改的任何设置使其正常工作。您使用的是哪个excel版本?xl'10。。。我刚刚复制了您的代码,粘贴到模块中,然后单击了“运行”。它在xl2007上不起作用..:它怎么不起作用?有错误吗?