简体   繁体   English

使用sendkeys将数据从vb.net datagrid复制到excel

[英]Copy data from vb.net datagrid into excel using sendkeys

I Have this code in VBA as a macro 我在VBA中将此代码作为宏

Sub Test()
Dim Wkb As Workbook

Set Wkb = ActiveWorkbook
notepadID = Shell("C:\Program Files\Default Company Name\TestInstaller\TestApp.exe")

SendKeys "admin", True
SendKeys "{TAB}", True
SendKeys "nothing", True
SendKeys "{ENTER}", True
SendKeys "{ENTER}", True
SendKeys "^C"
Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys "^V"
Application.Wait (Now + TimeValue("0:00:02"))



End Sub

So what i'm trying to do is copy data from a datagrid to excel, but i'm having trouble with just trying to copy the 1st cell of the datagrid, but when i try to paste it manually, the data is there! 所以我想做的是将数据从Datagrid复制到excel,但是我在尝试复制datagrid的第一个单元时遇到了麻烦,但是当我尝试手动粘贴它时,数据就在那里了! what am i doing wrong? 我究竟做错了什么?

right after 之后

SendKeys "^C"
Application.Wait (Now + TimeValue("0:00:02"))

try using 尝试使用

ActiveCell.PasteSpecial

instead of 代替

AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys "^V"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM