Try this and let me know.
Code: Select all
#NoTrayIcon
Gui +AlwaysOnTop
Gui, Color, 111111
Gui, Font, S10 EEAA99, Tahoma
Gui, Show, x131 y91 h200 w218,Copy
Gui, Add, Text, x5 y15 cFFCC00, A_C
Gui, Font, S14 EEAA99, Tahoma
Gui, Add, Edit, x43 y10 w170 h25 vCard1
Gui, Font, S10 EEAA99, Tahoma
Gui, Add, Text, x5 y48 cFFCC00, B_C
Gui, Add, Edit, x43 y44 w170 h25 vCard2
Gui, Add, Text, x5 y81 cFFCC00, C_C
Gui, Add, DropDownList, x43 y78 w70 h200 vCard3, A|B|C
Gui, Add, Text, x120 y81 cFFCC00, D_C
Gui, Add, DropDownList, x155 y78 w58 h200 vCard4, 01|02|03|04|05|06|07|08|09|10
Gui, Add, Text, x5 y114 cFFCC00, E_C
Gui, Add, DropDownList, x43 y112 w70 h200 vCard5, S1|T1|Q1
Gui, Add, Button, x132 y112 w80 h24 cFFCC00,Copy
Send {Tab}
#Persistent
WinGet, a_ID, ID, A
SetTimer, aa, 500
return
aa:
WinGet, a1_ID, ID, A
If ( a_ID != a1_ID )
k_ID = %a1_ID%
Return
; Note these lines will never run, so you don't need them.
FormatTime, TimeString
MsgBox The current time and date (time first) is %TimeString%
ButtonCopy:
Gui, Submit, NoHide
WinActivate, ahk_id %k_ID%
xl := ComObjCreate("Excel.application")
wb0 := xl.Workbooks.Open("C:\B.xlsx")
wb1 := xl.Workbooks.Open("C:\A.csv")
lRow := wb0.ActiveSheet.Range("F1048576").End(-4162).Row
aRow := wb1.ActiveSheet.Range("A1048576").End(-4162).Row ; The count of rows in A.csv, if column A can be empty then choose one that won't be...
wb1.ActiveSheet.Range("A1:D" . aRow).copy(wb0.ActiveSheet.Cells(lRow+3, 6)) ; This change will cover cases where there are more than 100 rows in A.
wb0.ActiveSheet.Cells(lRow+3, 1).value := "Date"
wb0.ActiveSheet.Cells(lRow+3, 2).value := "Group1"
wb0.ActiveSheet.Cells(lRow+3, 3).value := "Group2"
wb0.ActiveSheet.Cells(lRow+3, 4).value := "Group3"
wb0.ActiveSheet.Cells(lRow+3, 5).value := "Group4"
FormatTime, TimeString,,M/d/yy HH:mm
Loop % aRow -1 ; Loop the number of rows from A.csv -1 for headers, if there are no headers remove the the `-1`
{
offset := A_Index + 3
wb0.ActiveSheet.Cells(lRow+offset, 1).value := TimeString
wb0.ActiveSheet.Cells(lRow+offset, 2).value := card5
wb0.ActiveSheet.Cells(lRow+offset, 3).value := card3 card4
wb0.ActiveSheet.Cells(lRow+offset, 4).value := card2
wb0.ActiveSheet.Cells(lRow+offset, 5).value := card1
}
wb0.Save()
wb1.Close()
wb0.Close()
xl.Quit()
xl := ""
return
GuiClose:
ExitApp
Looks like it works in my small tests.
*Edit: Changed the last A row calc to match the method you originally used for the last B row for consistency.
*Edit2: Made a change to accomodate more than 100 rows in A.