AutoHotkey's ComObjActive handle to specific Worksheet

你。 提交于 2019-12-04 21:13:36

one way is to store the active workbook object in a variable like this

#Persistent

oExcel := ComObjActive("Excel.Application")
this_book := oExcel.ActiveWorkbook
SetTimer, xlRead, 10000
Return

xlRead:
{
  value := this_book.Sheets(1).Range("A1").Value
  MsgBox, %value%
}
Return

2nd way is to use ComObjGet with the full name of the active workbook if you know it before hand no need for the ControlGetText command just use the workbooks full name

#Persistent
SetTitleMatchMode, 2

ControlGetText, WorkBookName, Excel71, Microsoft Excel
oWorkbook := ComObjGet(WorkBookName)

SetTimer, xlRead, 10000
Return

xlRead:
{
  value := oWorkbook.Sheets(1).Range("A1").Value
  MsgBox, %value%
}
Return

You can also use ComObjGet with the full path of an excel file it will return the workbook object

#Persistent
fileselectfile, path

oWorkbook := ComObjGet(path)
SetTimer, xlRead, 10000
Return

xlRead:
{
  value := oWorkbook.Sheets(1).Range("A1").Value
  MsgBox, %value%
}
Return

Hope this helps you do what you need

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!