【发布时间】:2020-04-18 04:28:55
【问题描述】:
我正在与 AHK 一起使用 COM 控制 Excel。当前脚本的想法是让脚本在每次单击热键时执行不同的选项来冻结 Excel 工作表。在这种情况下,它是 ^f:: (CTRL+f)
我的想法是有一个 5 秒的计时器,并等待并发按下,每次都运行冻结功能。 5 秒后,脚本终止。
我觉得这是一个相当简单的 WaitKey 实现,但我没有运气。我无法完全理解如何使用 ErrorLevel 并用我的函数实现它。
任何帮助将不胜感激。我一直在查看文档和其他帖子,但无法弄清楚。我在下面写了一些伪代码,以便让您了解我正在尝试做什么。
press_cycle :=0
;; while KeyWait timer hasn't run out:
;; wait for additional presses of hotkey
;; if press
;; reset 5 sec timer
;; run cycle_freezing() again
cycle_freezing(){
if (press_cycle = 3){
MsgBox, "unfreezing"
xl.Application.ActiveWindow.FreezePanes := False
press_cycle := 0
}
if (press_cycle = 2){ ;; freeze header and selected column
MsgBox, "freezing header and selected"
;XL_Freeze(xl,Row:=header_row,Col:=column)
press_cycle := 3
}
if (press_cycle = 1){ ;; freeze header and first column
MsgBox, "freezing header and first col"
;XL_Freeze(xl,Row:=header_row,Col:="B")
press_cycle := 2
}
if (press_cycle = 0){ ;; freeze header
MsgBox, "freezing header"
XL_Freeze(xl,Row:=header_row,Col:="A")
press_cycle := 1
}
}
;***********************Freeze Panes********************************.
;~ XL_Freeze(XL,Row:="1",Col:="B") ;Col A will not include cols which is default so leave out if unwanted
;***********************Freeze Panes in Excel********************************.
XL_Freeze(xl,Row="",Col=""){
xl.Application.ActiveWindow.FreezePanes := False ;unfreeze in case already frozen
IfEqual,row,,return ;if no row value passed row; turn off freeze panes
xl.Application.ActiveSheet.Range(Col . Row+1).Select ;; Helps it work more intuitivly
;; 1 includes 1 not start at zero
xl.Application.ActiveWindow.FreezePanes := True
}
【问题讨论】:
标签: autohotkey