Link to home
Start Free TrialLog in
Avatar of beatified
beatifiedFlag for United States of America

asked on

Residual Data when running AutoHotKey Script on Excel data????

For some reason I run a AHK Script that calls an excel file and the returned data seems to be completely different and data that doesn't exist in the xlsx file. When I copy the data to a brand new xlsx file it seems to work properly. Is there residual data in the xlsx file?

Also I am trying to call a specific sheet in the work book and it doesn't seem to be working? As I see it this is the main problem as I don't believe the problem would exist if I called the sheet correctly.

#Warn,UseUnsetLocal
#NoEnv
#SingleInstance Force
SetBatchLines,-1

SourceFile:="C:\Documents and Settings\Administrator\Desktop\Working.xlsx"
DepNum:=14871
;InputBox, DepNum, Deposit Number, Enter the Deposit Number you would like to process
NumberColumns:=9
NumberRows:=30

Output:=""
ColumnLetters:=["A","B","C","D","E","F","G","H","I"]
oWorkbook:=ComObjGet(SourceFile)
oExcel.Sheets(DepNum).Select
ExcelCells:=Object()
Loop,%NumberRows%
{
  If (A_Index=1 or A_Index=2)
    Continue ; ignore first row
  CurrentRow:=A_Index
  Loop,%NumberColumns%
  {
    If (A_Index=1)
      Continue ; ignore column A
    If (A_Index=6)
      SetFormat,Float,6.2
    If (A_Index=7 or A_Index=9)
      SetFormat,Float,6.0
    CurrentColumn:=ColumnLetters[A_Index]
    CurrentCell:=CurrentColumn . CurrentRow
    ExcelCells[CurrentColumn,CurrentRow]:=oWorkbook.Worksheets(1).Range(CurrentCell).Value
    If (A_Index=2)
      Output:=Output . "10" . ExcelCells[CurrentColumn,CurrentRow] . " - "
    Else
      Output:=Output . ExcelCells[CurrentColumn,CurrentRow] . " - "
    If (A_Index=9)
      StringTrimRight,Output,Output,3
  }
  Output:=Output . "`n"
}
MsgBox, 3, Correct?, Is this the information You would like to process? (press Yes or No or Cancel to quit) `n%Output%
IfMsgBox Yes
    MsgBox You pressed Yes.
IfMsgBox No
	MsgBox You pressed No.
else
    MsgBox You pressed Cancel.
ExitApp

Open in new window


Working
Working.xlsx

Not Working
-Working.xlsx
ASKER CERTIFIED SOLUTION
Avatar of beatified
beatified
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial