ahk Run VBA Macro ERROR

Get help with using AutoHotkey and its commands and hotkeys
cgx5871
Posts: 10
Joined: 26 Jul 2018, 14:02

ahk Run VBA Macro ERROR

03 Aug 2019, 21:46

  • A1
    A2
    A3



    Date
    1-Mar
    1-Apr
    Hello
VBA Code:

Code: Select all

Sub Ahk_MButton()
    Select Case Selection.Address
        Case "$A$1"
            ActiveSheet.Range("$A$7:$A$9").AutoFilter Field:=1, Criteria1:=Array("Hello"), Operator:= _
                xlFilterValues
        Case "$A$2"
            ActiveSheet.Range("$A$7:$A$9").AutoFilter Field:=1, Operator:= _
                xlFilterValues, Criteria2:=Array(1, "4/1/2019")
        Case "$A$3"
            ActiveSheet.Range("$A$7:$A$9").AutoFilter Field:=1
    End Select
End Sub
Ahk Code:

Code: Select all

#NoEnv	
	#SingleInstance force      	
	#Persistent	
	GroupAdd ,Excel,ahk_class XLMAIN
	GroupAdd ,Excel,ahk_class wndclass_desked_gsk
Return
#IfWinActive,ahk_Group Excel
MButton::
	s=%A_ThisHotkey%
	StringReplace,s,s,~
	StringReplace,s,s,+,Shift_
	StringReplace,s,s,^,Ctrl_
	StringReplace,s,s,!,Alt_
	StringReplace,s,s,#,Win_
	s:="Ahk_" . s
	If oExcel:=Excel_Get(), oExcel.Run(s)
return  
Excel_Get(WinTitle="ahk_class XLMAIN") {	
		ControlGet, hwnd, hwnd, , Excel71, %WinTitle%
		If !hwnd
				return
		Window := Acc_ObjectFromWindow(hwnd, -16)
		Loop
				try
		Application := Window.Application
		catch
		ControlSend, Excel71, {esc}, %WinTitle%
		until !!Application
		return Application
	}
Acc_Init(){
	Static	h
	If Not	h
		h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromWindow(hWnd, idObject = 0){
	Acc_Init()
	If	DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
	Return	ComObjEnwrap(9,pacc,1)
}

When Case "$A$2" Run Error, Others OK

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], inseption86 and 231 guests