Cancel = True
End Sub
Code: Select all
~LButton::{
if (A_PriorHotkey != "~LButton" or A_TimeSincePriorHotkey > 400)
{
KeyWait "LButton"
return
}
Cancel:=true
}
Code: Select all
~LButton::{
if (A_PriorHotkey != "~LButton" or A_TimeSincePriorHotkey > 400)
{
KeyWait "LButton"
return
}
Cancel:=true
}
class Workbook_Events
Code: Select all
#Requires AutoHotkey v2.0
Persistent
; Create an instance of Excel
xlApp := ComObject("Excel.Application")
; Make xlApp visible
xlApp.Visible := true
; Add a new workbook
MyWb := xlApp.Workbooks.Add()
; Create a new instance of Workbook_Events and connect MyWb to it.
ComObjConnect(MyWb, Workbook_Events() )
class Workbook_Events
{
; Note: The docs indicate that "Cancel" is the third parameter, but it seems to be the first.
; https://learn.microsoft.com/en-us/office/vba/api/Excel.Workbook.SheetBeforeRightClick
; Event SheetBeforeRightClick(Sh As Object, Target As Range, Cancel As Boolean)
SheetBeforeRightClick(&Cancel, Target, Sh, wkb) {
; Cancel = False when the event occurs. If the event procedure sets this argument to True, the default right-
; click action isn't performed when the procedure is finished.
Cancel := -1
MsgBox "Address> " Target.Address "`nSh.Name> " Sh.Name "`nwkb.Name> " wkb.Name
}
}
Code: Select all
Persistent
XLSht := ComObjActive("Excel.Application").ActiveSheet
ComObjConnect(XLSht, "Sht_")
Sht_BeforeRightClick(&cancel, *)
{
cancel := true
}
Yeah, I was pretty confused at first. Turns out the docs are wrong?flyingDman wrote:Nice catch !! It did not occur to me to change the order....
Code: Select all
#Requires AutoHotkey v2.0
Persistent
; Create an instance of Excel
xlApp := ComObject("Excel.Application")
; Make xlApp visible
xlApp.Visible := true
; Add a new workbook
MyWb := xlApp.Workbooks.Add()
; Create a new instace of Workbook_Events and connect MyWb to it.
ComObjConnect(MyWb, Workbook_Events() )
class Workbook_Events
{
__Call(Name, Params) {
EventInfo := ""
for i, val in Params
{
if !ComObjType(val)
EventInfo .= "Arg#: " i
. "`nNot an object`n`n"
else
EventInfo .= "Arg#: " i
. "`nVarType: " ComObjType(val)
. "`nName: " ComObjType(val, "Name")
. "`nIID: " ComObjType(val, "IID")
. "`nClass: " ComObjType(val, "Class")
. "`nCLSID: " ComObjType(val, "CLSID") "`n`n"
}
MsgBox "Event: " Name "`n`nParams:`n`n" EventInfo, Name
}
; Event SheetBeforeRightClick(Sh As Object, Target As Range, Cancel As Boolean)
; Note: The docs seems to indicate that "Cancel" is the third parameter, but it seems to be the first.
; https://learn.microsoft.com/en-us/office/vba/api/Excel.Workbook.SheetBeforeRightClick
SheetBeforeRightClick(&Cancel, Target, Sh, wkb) {
; Canacel = False when the event occurs. If the event procedure sets this argument to True, the default right-
; click action isn't performed when the procedure is finished.
Cancel := -1
MsgBox "Address> " Target.Address "`nSh.Name> " Sh.Name "`nwkb.Name> " wkb.Name, "SheetBeforeRightClick"
}
}
Code: Select all
Persistent
XLSht := ComObjActive("Excel.Application").ActiveSheet
ComObjConnect(XLSht, "Sht_")
Sht_BeforeRightClick(&cancel, cell, *)
{
cancel := true
msgbox cell.parent.name "`n" cell.parent.parent.name "`n" cell.value "`n" cell.address(0,0)
}
how to ComObjConnect existing workbook (like test.xls). and apply toggle every ActiveSheetflyingDman wrote: ↑28 May 2023, 19:57You can always use cell.parent.name and cell.parent.parent.name to get the name of the sheet and the name of workbook:Possible application of this:Code: Select all
Persistent XLSht := ComObjActive("Excel.Application").ActiveSheet ComObjConnect(XLSht, "Sht_") Sht_BeforeRightClick(&cancel, cell, *) { cancel := true msgbox cell.parent.name "`n" cell.parent.parent.name "`n" cell.value "`n" cell.address(0,0) }
Spoiler
Code: Select all
MyWb := xlApp.ActiveWorkbook
Code: Select all
Persistent
Xl := ComObject("Excel.Application")
XLWb := Xl.Workbooks.Open("C:\Users\xxx\Scripts\Test.xlsx")
Xl.visible := true
;~ or XLWb := ComObjActive("Excel.Application").ActiveWorkBook
ComObjConnect(XLWb, "Wb_")
Wb_SheetBeforeRightClick(&cancel, cell, sheet, wkb, *)
{
cancel := true
lst .= cell.address(0,0) "`n"
lst .= sheet.name "`n"
lst .= wkb.name
msgbox lst
}