如何使用SendKeys从DOS应用程序复制粘贴到Excel? [英] How to copy-paste from DOS application to Excel using SendKeys?

查看:78
本文介绍了如何使用SendKeys从DOS应用程序复制粘贴到Excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模拟此操作:

  • 激活另一个应用程序,
  • 发送击键ctrl + c,
  • 返回Excel,
  • 发送按键ctrl + v

并在单元格中具有该值.

这是DOS窗口样式的应用程序,因此击键是管理它的唯一方法.

我设法激活并在DOS风格的应用程序中输入了ENTER之类的击键,但是当我尝试 ctrl + C 时,它什么也没做./p>

我尝试使用以下方法在Excel VBA中对其进行仿真:

  Range("E7").SelectSendKeys"^ c"范围("G7").选择SendKeys"^ v" 

不会复制E7值,但是会高亮显示G7(粘贴目标),就像选择复制它一样.

注意:我不是试图将内容从Excel复制到Excel,而是要使用Excel执行击键.

解决方案

我今天遇到了同一问题.

我通过将CTRL-C发送到应用程序后稍等片刻来解决它.如果立即执行另一个脚本行,似乎什么也不会复制.

  SendKeys"^ c"WScript.Sleep 100'在CTRL + C之后稍等(否则将不会复制任何内容) 

实际上,切换到另一个应用程序并发送CTRL + V时似乎也会发生相同的问题.再次,我通过稍等片刻解决了该问题:

  AppActivate"Microsoft Excel"WScript.Sleep 100'使窗口处于活动状态后稍等SendKeys"^ v" 

I'm trying to simulate this action:

  • activate another application,
  • send keystroke ctrl+c,
  • go back to Excel,
  • send key stroke ctrl+v

and have that value in a cell.

It's a DOS window style application, so keystroke is the only way to manage it.

I managed to activate and to input keystrokes such as ENTER into that DOS style application, but when I try ctrl+C it is not seen to do anything.

I tried simulating it in Excel VBA with:

Range("E7").Select
SendKeys "^c"
Range("G7").Select
SendKeys "^v"

The E7 value is not copied, but G7 (paste destination) is highlighted as if it was selected for copying.

Note: I am not trying to copy things from Excel to Excel, but to execute keystrokes using Excel.

解决方案

I ran into the same issue today.

I solved it by waiting a bit after sending CTRL-C to the application. It seems nothing is copied if you immediately execute another script line.

SendKeys "^c"
WScript.Sleep 100 ' wait a bit after CTRL+C (otherwise nothing is copied)

In fact, the same issue seems to happen when switching to another app and sending CTRL+V. Again, I solved it by waiting a bit:

AppActivate "Microsoft Excel"
WScript.Sleep 100 ' wait a bit after making window active
SendKeys "^v"

这篇关于如何使用SendKeys从DOS应用程序复制粘贴到Excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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