We help IT Professionals succeed at work.

Help with a AutoHotKey Script

Ok I'm practically pulling my hair out on this. I have to be honest with myself and who ever helps me (cough, cough, "Joe"). I am just having a horrible time figuring out what I desire to achieve.

My Goal is this...
Using an Excel workbook and specific sheet I want the data in the range of B3:I3 to be stored as Variables preferably like this. eg. Apt1, Let1, Payee1, Amt1,  CheckNum1, PmtType1, ReceiptNum1 then Apt2, Let2, and so on. If its easier to do in a different way I'm fine with that.

This should loop the by the value of F1 on that sheet witch counts the number of fields that have a value in the Payment amount column.

All I want to do is have a list of variables in the end that I can call individually later.
A simple MsgBox showing limited data just to show it it working would be great but I can do that as well.
I know I am asking a lot but I am hoping that its not as much for someone else as it would be for me

So the UI would be...
Run the script.
Get a dialog asking for the Deposit number to process and set that as the worksheet variable.
and then variables are created.

Formatting of the sheet will always be the same.
All preceeding zeros should stay in tact on Apt #, Check #, and Receipt #
If Letter is blank I would like it to store a variable witch returns nothing (ie No space)
If possible I would like to store the date as Year1, Month1, and Day1 instead of Date1

I think that covers it all I hope I can do something in return for the lucky one.

Here is a sample of the workbook... Sample.xlsx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Hi Stuart,
Thanks for the sample workbook...that's very helpful! I should be able to take a run at this later in the day. Regards, Joe

Author

Commented:
Beyond grateful for your help Joe!!!!!!!
Developer
Fellow 2017
Most Valuable Expert 2018
Commented:
Hi Stuart,

> I'm practically pulling my hair out on this.

This post should help to retain your hair.

> B3:I3 to be stored as Variables preferably like this. eg. Apt1, Let1, Payee1, Amt1, CheckNum1, PmtType1, ReceiptNum1 then Apt2, Let2, and so on.

Done.

> If its easier to do in a different way I'm fine with that.

A little easier to do with real arrays instead of pseudo arrays, but since you prefer the latter, I did it that way.

> This should loop by the value of F1 on that sheet

Done.

> All I want to do is have a list of variables in the end that I can call individually later.

Done.

> A simple MsgBox showing limited data just to show it working would be great

Done. Here's a sample:

stuart test result sample
> I know I am asking a lot

Yes, on the hairy edge of not being in the pro bono range. :)

> So the UI would be

I presume the UI is yours.

> All preceding zeros should stay in tact on Apt #, Check #, and Receipt #

Done.

> If Letter is blank I would like it to store a variable which returns nothing (ie No space)

Done.

> If possible I would like to store the date as Year1, Month1, and Day1 instead of Date1

Done (it makes all months and days two digits).

> I think that covers it all

If so, the AutoHotkey script below does it. Regards, Joe

NumRowsCell:="F1"
ExcelFile:="c:\temp\StuartDepositSample.xlsx"
If (!FileExist(ExcelFile))
{
  MsgBox,4112,Fatal Error,Input file does not exist:`n%ExcelFile%
  ExitApp
}
oExcel:=ComObjCreate("Excel.Application")
If (!IsObject(oExcel))
{
  MsgBox,4112,Fatal Error,Error trying to create Excel object
  ExitApp
}
oExcel.Visible:=False ; set to True if you want it to be visible
oWorkbook:=oExcel.Workbooks.Open(ExcelFile)
If (!IsObject(oWorkbook))
{
  MsgBox,4112,Fatal Error,Error trying to open Workbook
  ExitApp
}
NumRows:=oWorkbook.Worksheets(1).Range(NumRowsCell).Value
If NumRows is not number
{
  MsgBox,4112,Fatal Error,Number of rows must be a positive number:`n%NumRows%
  ExitApp
}
If ((NumRows="") or (NumRows<1))
{
  MsgBox,4112,Fatal Error,Number of rows must be a positive number:`n%NumRows%
  ExitApp
}
StartingRow:=3
Loop,%NumRows%
{
  Row:=StartingRow+A_Index-1

  Cell:="B" . Row
  Apt%A_Index%:=oWorkbook.Worksheets(1).Range(Cell).Value

  Cell:="C" . Row
  Let%A_Index%:=oWorkbook.Worksheets(1).Range(Cell).Value
  If Let%A_Index% is space
    Let%A_Index%:=""

  Cell:="D" . Row
  Date:=oWorkbook.Worksheets(1).Range(Cell).Value
  DateArray:=StrSplit(Date,"/")
  Month%A_Index%:=SubStr("00" . DateArray[1],-1)
  Day%A_Index%:=SubStr("00" . DateArray[2],-1)
  Year%A_Index%:=SubStr("00" . DateArray[3],-1)

  Cell:="E" . Row
  Payee%A_Index%:=oWorkbook.Worksheets(1).Range(Cell).Value

  Cell:="F" . Row
  Amt%A_Index%:=oWorkbook.Worksheets(1).Range(Cell).Value

  Cell:="G" . Row
  CheckNum%A_Index%:=oWorkbook.Worksheets(1).Range(Cell).Value

  Cell:="H" . Row
  PmtType%A_Index%:=oWorkbook.Worksheets(1).Range(Cell).Value

  Cell:="I" . Row
  ReceiptNum%A_Index%:=oWorkbook.Worksheets(1).Range(Cell).Value
}
oWorkbook.Close(0)
oExcel.Quit
ObjRelease(oExcel)

; for testing - show all variables
Loop,%NumRows%
{
  Row:=StartingRow+A_Index-1
  Apt:=Apt%A_Index%
  Let:=Let%A_Index%
  Year:=Year%A_Index%
  Month:=Month%A_Index%
  Day:=Day%A_Index%
  Payee:=Payee%A_Index%
  Amt:=Amt%A_Index%
  CheckNum:=CheckNum%A_Index%
  PmtType:=PmtType%A_Index%
  ReceiptNum:=ReceiptNum%A_Index%
  MsgBox,4160,Test Results,Row %Row%:`n%Apt%`n%Let%`n%Month%`n%Day%`n%Year%`n%Payee%`n%Amt%`n%CheckNum%`n%PmtType%`n%ReceiptNum%
}
ExitApp

Open in new window

Author

Commented:
Perfect!!!

Thanks so much for all your help you have been indispensable to me.

Stuart

Author

Commented:
To say Joe is helpful is an understatement I just hope his generosity and knowledge is not taken advantage of.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're very welcome, Stuart, and my thanks back at you for the kind words...much appreciated! Regards, Joe