从A2-A1000&;复制Excel循环;填写新表格

从A2-A1000&;复制Excel循环;填写新表格,excel,autohotkey,Excel,Autohotkey,我使用这个脚本从“201605191947.xlsx”中复制特定的单元格,然后填写“Contact.xlsx”,这是为了创建一个.CSV 它可以工作,但我不明白如何使它从第2行循环到第1000行 对不起,我的英语 #SingleInstance, Force SetDefaultMouseSpeed, 0 IfWinExist 201605191947.xlsx { WinActivate WinWaitActive 201605191947.xlsx } else IfWinNotExist

我使用这个脚本从“201605191947.xlsx”中复制特定的单元格,然后填写“Contact.xlsx”,这是为了创建一个.CSV

它可以工作,但我不明白如何使它从第2行循环到第1000行

对不起,我的英语

#SingleInstance, Force
SetDefaultMouseSpeed, 0

IfWinExist 201605191947.xlsx
{
WinActivate
WinWaitActive 201605191947.xlsx
}
else
IfWinNotExist 201605191947.xlsx
{
run, C:\Users\iViLL\Google Drive\Doc\201605191947.xlsx
WinWait 201605191947.xlsx
Sleep 4000
}
Clipboard=
Sleep 500

RControl::
{
BookingBox := ComObjActive("Excel.Application")

MyVar1 := BookingBox.Range("A2").text

MyVar2 := BookingBox.Range("B2").text

MyVar3 := BookingBox.Range("C2").text

MyVar4 := BookingBox.Range("G2").text

MyVar5 := BookingBox.Range("I2").text

MyVar6 := BookingBox.Range("J2").text

MyVar7 := BookingBox.Range("K2").text

MyVar8 := BookingBox.Range("M2").text

MyVar9 := BookingBox.Range("N2").text

MyVar10 := BookingBox.Range("P2").text

MyVar11 := BookingBox.Range("Q2").text

MyVar12 := BookingBox.Range("U2").text

MyVar13 := BookingBox.Range("AB2").text

IfWinExist Contact.xlsx
    WinActivate
WinWaitActive Contact.xlsx
Sleep 500
KeyWait, LButton, D
Sleep 1000
FileRead, Clipboard, C:\Program Files\AutoHotkey\Google csv.txt
MouseMove, 329, 189
Click
Send, ^v
Send, {Enter}
Sleep 1000
FileRead, Clipboard, C:\Program Files\AutoHotkey\comma.txt
MyVar19 := Clipboard
MouseMove, 329, 189
Click
SendRaw % MyVar2
Sleep 300
Send, %A_Space%
Sleep 300
SendRaw % MyVar1
Sleep 300
Send, %A_Space%
Sleep 300
SendRaw % MyVar6
SendRaw % MyVar19
Send, %A_Space%
Sleep 300
SendRaw % MyVar1
SendRaw % MyVar19
Send, %A_Space%
Sleep 300
SendRaw % MyVar6

Loop 6
{
SendRaw % MyVar19
}
Sleep 300
SendRaw % MyVar2
Sleep 300
FileRead, Clipboard, C:\Program Files\AutoHotkey\Quotation mark.txt
MyVar18 := Clipboard
Loop 17
{
SendRaw % MyVar19
}
SendRaw % MyVar18
Send, Date:
Sleep 300
SendRaw % MyVar10
Send, {Enter}
Sleep 1000
MouseMove, 329, 189
Click
SendRaw % MyVar11
Send, {Enter}
Sleep 1000
MouseMove, 329, 189
Click
Send, Price:
SendRaw % MyVar4
Sleep 300
Send, {Enter}
Sleep 1000
MouseMove, 329, 189
Click
Send, Mark1:
SendRaw % MyVar5
Sleep 300
Send, {Enter}
Sleep 1000
MouseMove, 329, 189
Click
Send, Mark2:
SendRaw % MyVar12
Sleep 300
SendRaw % MyVar18
SendRaw % MyVar19
Send, %A_Space%
Send, %A_Space%
Sleep 300
Send, * My Contacts,* Home,%A_Space%
SendRaw % MyVar9
SendRaw % MyVar19
Send, %A_Space%
Sleep 300
Send, Work
SendRaw % MyVar19
Send, %A_Space%
SendRaw % MyVar3
SendRaw % MyVar19
Send, %A_Space%
Sleep 300
Send, Home
SendRaw % MyVar19
Send, %A_Space%
SendRaw % MyVar8
SendRaw % MyVar19
Send, %A_Space%
Sleep 300
Send, Home
SendRaw % MyVar19
Send, %A_Space%
Clipboard := MyVar7
StringReplace, clipboard, clipboard, %A_Space%,, all
MyVar7 := Clipboard
SendRaw % MyVar7
SendRaw % MyVar19
Send, %A_Space%
Sleep 300
Send, %A_Space%:::%A_Space%
Clipboard := MyVar13
StringReplace, clipboard, clipboard, %A_Space%,, all
MyVar13 := Clipboard
SendRaw % MyVar13
SendRaw % MyVar19
Send, %A_Space%
Sleep 300
SendRaw % MyVar7
SendRaw % MyVar19
Send, %A_Space%
Sleep 300
Send, %A_Space%:::%A_Space%
SendRaw % MyVar13
Sleep 300
Loop 6
{
SendRaw % MyVar19
Send, %A_Space%:::%A_Space%
Sleep 100
}
Sleep 100
Send {Enter}
}
描述 我将创建一个函数,从Excel中捕获所需的行。然后在需要时调用该函数

在本例中,我执行以下操作:

  • 声明我的功能
  • 创建ComObject连接并将其保存到变量,就像您已经做的那样
  • 创建一个循环来处理excel文档中的10行,当您完善脚本的其余部分时,您可以将这个数字扩大到您想要处理的行数
  • 创建一个嵌套循环以显示结果,并让您了解如何使用数据。这是我开始插入你的动作的地方
自动热键代码示例
funGetRow(Row, ComObject) {

    Output := Object()

    Output.insert(ComObject.Range("A" . Row).text)
    Output.insert(ComObject.Range("B" . Row).text)
    Output.insert(ComObject.Range("C" . Row).text)
    Output.insert(ComObject.Range("G" . Row).text)
    Output.insert(ComObject.Range("I" . Row).text)
    Output.insert(ComObject.Range("J" . Row).text)
    Output.insert(ComObject.Range("K" . Row).text)
    Output.insert(ComObject.Range("M" . Row).text)
    Output.insert(ComObject.Range("N" . Row).text)
    Output.insert(ComObject.Range("P" . Row).text)
    Output.insert(ComObject.Range("Q" . Row).text)
    Output.insert(ComObject.Range("U" . Row).text)
    Output.insert(ComObject.Range("AB" . Row).text)

    return, % Output
    } ; end function funGetRow

; open connection to excel
BookingBox := ComObjActive("Excel.Application")

; lets loop through 10 lines in the excel doc
; first time through the loop a_index will be 1, each additional
Loop, 10  
{
    ; add one to the line because we want to skip the header line
    RowNumber := a_index + 1

    ; go get the important values from the deisred row
    ; the function funGetRow will return an array
    ThisRow := funGetRow( RowNumber, BookingBox )

    strMessage := "Row number " . RowNumber . " has the following values"
    ; loop through all the values in the row and build a little report of them
    For Index, Value in ThisRow {
        strMessage .= "`n[" . Index . "] = '" . Value . "'"
        } ; next value

    ; insert some arbitrary values to show how to access a value from the array for this line
    strMessage .= "`n`nValue 3 in the array is = '" . ThisRow[3] . "'"
    strMessage .= "`n`nValue 10 in the array is = '" . ThisRow[10] . "'"

    MsgBox, % strMessage

    } ; next