我試圖複製datagridview的值出類拔萃脫穎而出,到目前爲止,我有這個代碼的工作,但只有線性複製vb.net數據網格值與VBA的SendKeys
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 "{LEFT}", True
SendKeys ("^C")
Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
ActiveCell.Offset(0, 0).Select
Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.PasteSpecial
Application.Wait (Now + TimeValue("0:00:01"))
AppActivate "Inventory"
SendKeys "{TAB}", True
SendKeys ("^C")
Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste
End Sub
我願意這樣做是,從數據網格複製數據,datagrid由4行和4列組成,我想從datagrid使用vba sendkeys將所有內容複製到我的excel中。先謝謝你!
編輯:
我知道有這樣的代碼,但輸出是對角線
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
Dim i As Integer
Dim j As Integer
i = 1
j = 1
SendKeys ("^C")
Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
ActiveCell.Offset(1, 1).Select
'Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.PasteSpecial
Application.Wait (Now + TimeValue("0:00:01"))
AppActivate "Inventory"
SendKeys "{TAB}", True
If Not IsEmpty(ActiveCell.Value) Then
Do While Cells(i, j).Value = Cells(i, j + 3).Value
j = j + 1
SendKeys ("^C")
Application.Wait (Now + TimeValue("0:00:02"))
AppActivate "MicroSoft Excel"
Application.Wait (Now + TimeValue("0:00:02"))
ActiveCell.Offset(i, j).Select
'Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.PasteSpecial
Application.Wait (Now + TimeValue("0:00:01"))
AppActivate "Inventory"
SendKeys "{TAB}", True
If i = 4 Then
i = i = 0
j = j + 1
End If
Loop
End If
End Sub
我對VB並沒有真正的經驗和發送鍵,但你不能只是循環槽?例如'ActiveCell.Offsett(y,x).Select' –
@BennoGrimm先生,您能否詳細說明一下?我使用偏移量,但參考不在單元格旁邊,而是在對角線位置 – UserSeriously
您能否通過_It的作用解釋您的意思,但僅限於linear_? –