I've been working on a simple excel script, but I seem to be encountering this error. The following code works fine:
Code: Select all
oExcel := ComObjActive("Excel.Application") ;Connects to the active Excel application
FinishedEdit := "N"
;While (FinishedEdit == "N")
;{
;Destroy Previous run of the Gui
Gui, Destroy
Gui, Add, Text,, Enter in the row (a number) to make amendments:
Gui, Add, Text,, Enter in the start column (letters):
Gui, Add, Text,, Enter in the end column (letters):
Gui, Add, Text,, Enter in the number you want to add (use a negative number to subtract) to each cell:
Gui, Add, Edit, vRow ym
Gui, Add, Edit, vStartCol
Gui, Add, Edit, vEndCol
Gui, Add, Edit, vNumtoAdd
Gui, Add, Button, default xm+450 w80, OK
Gui, Show,, Parameters
return
GuiClose:
ButtonOK:
Gui, Submit
if Row is integer
{
ValidRow := 1
} else {
ValidRow := 0
}
if NumtoAdd is number
{
ValidNumToAdd := 1
} else {
ValidNumToAdd := 0
}
if StartCol is alpha
{
if (StartCol != "")
{
ValidStartCol := 1
} else {
ValidStartCol := 0
}
} else {
ValidStartCol := 0
}
if EndCol is alpha
{
if (EndCol != "")
{
ValidEndCol := 1
} else {
ValidEndCol := 0
}
} else {
ValidEndCol := 0
}
while (ValidRow == 0)
{
InputBox, Row, Enter a number for the Row, Row entered was not a number. Try again:,, 300, 150
if Row is integer
{
ValidRow := 1
}
}
while (ValidStartCol == 0)
{
InputBox, StartCol, Enter a letter for the Column, Start Column Entered was not a letter. Try again:,, 300, 150
if StartCol is alpha
{
if (StartCol != "")
{
ValidStartCol := 1
}
}
}
while (ValidEndCol == 0)
{
InputBox, EndCol, Enter a letter for the Column, End Column Entered was not a letter. Try again:,, 300, 150
if EndCol is alpha
{
if (EndCol != "")
{
ValidEndCol := 1
}
}
}
while (ValidNumToAdd == 0)
{
InputBox, NumtoAdd, Enter a number for the Number to Add, Number to Add entered was not a number. Try again:,, 300, 150
if NumtoAdd is integer
{
ValidNumToAdd := 1
}
}
;Converts Start Column and End Column into Column Number
StartColumn := oExcel.Columns(StartCol).Column
FinishColumn := oExcel.Columns(EndCol).Column
Iterations := FinishColumn - StartColumn + 1
loop, %Iterations%
{
if (oExcel.Cells(Row, StartColumn + A_Index -1).Value == "")
{
;Set all interested cell values to '0' if blank
oExcel.Cells(Row, StartColumn + A_Index -1).Value := 0
}
oExcel.Cells(Row, StartColumn+A_Index-1).Value := oExcel.Cells(Row, StartColumn+A_Index-1).Value + NumtoAdd
}
InputBox, Revert, Are changes ok?, Everything ok? (Y) or Undo changes? (U),, 300, 150
while ((Revert != "Y") AND (Revert != "U"))
{
InputBox, Revert, Invalid Input, Everything ok? (Y) or Undo changes? (U),, 300, 150
}
if (Revert == "U")
{
loop, %Iterations%
{
oExcel.Cells(Row, StartColumn + A_Index-1).Value := oExcel.Cells(Row, StartColumn + A_Index-1).Value - NumtoAdd
}
}
InputBox, FinishedEdit, Finished Processing Entries?, Have you finished making changes? (Y/N),, 300, 150
while ((FinishedEdit != "Y") AND (FinishedEdit != "N"))
{
InputBox, FinishedEdit, Invalid Input, Have you finished making changes? (Y/N),, 300, 150
}
;}
ExitApp
Thanks