使用AutoHotKey的Excel Com对象随机不可见

时间:2018-11-28 09:19:08

标签: autohotkey

我使用以下脚本从IrfanView获取Imagepath,然后转到包含Imagepath的Excel单元格。

;Excel Column name that contains imagename
ImageColumn=A
;handle to running application
try XL := ComObjActive("Excel.Application")
; Create COM If no Excel is running
Catch {
    MsgBox % "no existing Excl object:  Need to create one"
XL := ComObjCreate("Excel.Application")
}
;Get ImagePath from Free image viewer Irfanview image properties dialog
ControlGetText, ImagePath, Edit3, IrfanView - Image properties
;And close the dialog
PostMessage, 0x112, 0xF060,,, IrfanView - Image properties
;Loop until Excel activate to workaround for excel randomly not get active state
Loop
 {
     WinActivate, ahk_exe EXCEL.EXE
     IfWinActive, ahk_exe EXCEL.EXE
        Break
     Sleep 200
 }
;Get Excel activecell
DataColNum:=XL.Activecell.Column
;Make COM obj visible to ensure visibility
XL.Application.ActiveWindow.Visible := 1
;Find ImageName in the column
XL.Application.ActiveSheet.Range(XL.Cells(Floor(XL.Application.WorkSheetFunction.Match(ImagePath,XL.Application.ActiveSheet.Range(ImageColumn . ":" . ImageColumn),0)),DataColNum).Address).Activate

但是此脚本会随机丢失,以至于我们无法看到Excel窗口,即Activecell仍从键盘接收输入,但该窗口不可见。

0 个答案:

没有答案