We help IT Professionals succeed at work.

Set a variable to a sheet and cell in Excel AutoHotKey

I am trying to set a variable to the value of Cell F1 on sheet %DepNum% But not figuring it out as of yet.

Cell F1 is a countif in Excel to count the number of fields that aren't blank.

SourceFile:="C:\Users\beatified\Desktop\AHK\Copy of Deposit Form.xlsx"
InputBox, DepNum, Deposit Number, Enter the Deposit Number you would like to process
NumberColumns:=9


Output:=""
ColumnLetters:=["A","B","C","D","E","F","G","H","I"]
oWorkbook:=ComObjGet(SourceFile)
oExcel.Sheets(DepNum).Select
ExcelCells:=Object()
NumberRows:=oWorkbook.Worksheets(DepNum).Range(F1).Value
Loop,%NumberRows%

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer
Fellow 2017
Most Valuable Expert 2018
Commented:
> I am trying to set a variable to the value of Cell F1 on sheet %DepNum%

This AutoHotkey snippet does it:

DepNum:=1
Cell:="F1"
oExcel:=ComObjActive("Excel.Application")
CellVal:=oExcel.Worksheets(DepNum).Range(Cell).Value
MsgBox % CellVal

Open in new window

That assumes the spreadsheet is open. If not, here's a snippet that also opens it:

ExcelFile:="c:\temp\test.xlsx"
DepNum:=1
Cell:="F1"
oExcel:=ComObjActive("Excel.Application")
oExcel.Visible:=False ; set to True if you want it to be visible
oWorkbook:=oExcel.Workbooks.Open(ExcelFile)
CellVal:=oWorkbook.Worksheets(DepNum).Range(Cell).Value
MsgBox % CellVal

Open in new window

Regards, Joe