简体   繁体   中英

Copy data from vb.net datagrid into excel using sendkeys

I Have this code in VBA as a macro

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! 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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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