Code: Select all
#SingleInstance, Force ; Allow only one running instance of the script
#Persistent ; Keep the script permanently running until terminated
#NoEnv ; Avoid checking empty variables for environment variables
#Warn ; Enable warnings to assist with detecting common errors
;#NoTrayIcon ; Disable the tray icon of the script
;SendMode, Input ; Method for sending keystrokes and mouse clicks
;SetWorkingDir, %A_ScriptDir% ; Set the working directory of the script
;SetBatchLines, -1 ; Run the script at maximum speed
;SetWinDelay, -1 ; The delay to occur after modifying a window
;SetControlDelay, -1 ; The delay to occur after modifying a control
;OnExit, ExitSub ; Run a subroutine or function when the script exits
;~Pause::Suspend ; Pause and suspend AHK script
1:: RunMSWordMacro("StepLeftSentence") ;Change to name of VBA Macro here StepLeftSentence or StepRightSentence or CursorToStartOfSentence
RunMSWordMacro(StepLeftSentence) { ;Change to name of VBA Macro here StepLeftSentence or StepRightSentence or CursorToStartOfSentence
GetWord().Run(StepLeftSentence) ;Change to name of VBA Macro here StepLeftSentence or StepRightSentence or CursorToStartOfSentence
}
GetWord() {
if !hwnd := WinActive("ahk_class OpusApp")
hwnd := WinExist("ahk_class OpusApp")
ControlGet, ControlHwnd, Hwnd,, _WwG1, ahk_id %hwnd%
Return AccObjectFromWindow(ControlHwnd, -16).Application
}
AccObjectFromWindow(hWnd, idObject = 0)
{
static IID_IDispatch := "{00020400-0000-0000-C000-000000000046}"
, IID_IAccessible := "{618736e0-3c3d-11cf-810c-00aa00389b71}"
, OBJID_NATIVEOM := 0xFFFFFFF0, VT_DISPATCH := 9, h := DllCall("LoadLibrary", Str, "oleacc", Ptr)
VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF
DllCall("ole32\CLSIDFromString", Str, idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, Ptr, &IID)
if DllCall("oleacc\AccessibleObjectFromWindow", Ptr, hWnd, UInt, idObject, Ptr, &IID, PtrP, pAcc) = 0
Return ComObjEnwrap(VT_DISPATCH, pAcc, 1)
}
[Mod edit: [code][/code] tags added.]
==================================
Hi. I tried using this script adapted from your script but I get this error (in the attachment). Can you please help me to fix it?