I need your help.
My aim is to copy data from two sheets of an Excel table (which is active) and to export them to a text file.
The good news: It almost works.
The bad news: It seems there is a problem with changing the sheet.
It doesn't copy the values of sheet 2.
Does sheet2 have to have a specific name, or doesn't its name matter?
I think sheet names don't matter here (I made some tests.)
That's the code:
Code: Select all
#SingleInstance force
F3::
Loop, 4
{
i++ ; Counter for Array
xl := ComObjActive("Excel.Application") ; Connect to the active Excel application
wb := excel.ActiveWorkbook ; Connect to active workbook
ws := excel.ActiveSheet ; Connect to active worksheet
cellArray := ["A1", "B1", "C1", "D1"] ; List of cells
cell := cellArray[i] ; Variable which accesses values of the array
Book.ws("Sheet1").Select ; Select first sheet
Sleep, 5
xl.Range(cell).copy ; Copy value of cell to Clipboard
Sleep, 5
a := Clipboard ; Copy Clipboard content to variable a
Sleep, 5
Book.ws("Sheet2").Select ; Select second sheet - DOES NOT WORK
Sleep, 5
xl.Range(cell).copy ; Copy value of cell to Clipboard
Sleep, 5
b := Clipboard ; Copy Clipboard content to variable b
Sleep, 5
FileAppend, %a% %b%, %A_ScriptDir%\Array.txt ; Write content of variable a and b to an external file
Sleep, 5
}
return
Thanks for any help!