VBA-带Sendkeys的CopyPasteCode [英] VBA - CopyPasteCode with Sendkeys

查看:103
本文介绍了VBA-带Sendkeys的CopyPasteCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在excel工作簿中使用IDE,并尝试执行以下代码.

I'm using IDE in a excel workbook and trying to do the below code.

Sub cpypaste()    
    Range("E7").Select    
    SendKeys ("^c"), True    
    Application.Wait (Now + TimeValue("00:00:01"))    
    Range("G7").Select        
    SendKeys ("^v"), True    
End Sub

并不是说我不知道​​执行此操作的替代方法,而是好奇为什么这样做不起作用.我尝试过使用键盘快捷键和cmdbutton运行此代码.任何帮助将不胜感激.

Not that I do not know alternate ways of doing it, but just curious why this is not working. I've tried running this code with keyboard shortcut and cmdbutton as well. Any help will be greatly appreciated.

推荐答案

使用sendKeys最多是粪便.我假设您是从代码"窗口启动代码的,因此,命令正在尝试引用该窗口.需要激活Excel才能接收命令.

Using sendKeys is fecal at best. I assume you are starting the code from the code window, and because of this, the commands are trying to refer to that window. Excel needs to be activated to receive the commands.

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

这篇关于VBA-带Sendkeys的CopyPasteCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆