Skip to content

Instantly share code, notes, and snippets.

@JoeGlines
Created October 5, 2022 20:45
Show Gist options
  • Save JoeGlines/bc8c8ac3edd8f4bbf9e6b84b607afe94 to your computer and use it in GitHub Desktop.
Save JoeGlines/bc8c8ac3edd8f4bbf9e6b84b607afe94 to your computer and use it in GitHub Desktop.
;~ #Include <default_Settings>
#SingleInstance,Force
;**************************************
SetTitleMatchMode 2
OBJID_NATIVEOM := -16
;********************if Word is active***********************************
ControlGet, hwnd, hwnd, , % "_WwG1", % "- Word ahk_class OpusApp" ;identify the hwnd for Word
;********************Now apply to which ever one is active***********************************
OBJ:=ObjectFromWindow(hwnd, OBJID_NATIVEOM)
;~ MsgBox % IsObject(obj)
MsgBox % Folder:= OBJ.Application.ActiveDocument.Path . "\" ;adding \ to the folder
MsgBox % FileName:=OBJ.Application.ActiveDocument.Name
MsgBox % "Full file path: " Folder . FileName
OBJ:=""
return
;***borrowd & tweaked from Acc.ahk Standard Library*** by Sean Updated by jethrow*****************
ObjectFromWindow(hWnd, idObject = -4){
if(h:=DllCall("LoadLibrary","Str","oleacc","Ptr"))
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)
}
/*
;********************if Word is active***********************************
If WinActive("Word"){
ControlGet, hwnd, hwnd, , % "_WwG1", % "- Word ahk_class OpusApp" ;identify the hwnd for Word
Word:=ObjectFromWindow(hwnd, OBJID_NATIVEOM)
Word.Selection.Font.Name := "Times New Roman"
Word.Selection.Font.Size := 12
Word:=""
} Else If WinActive("Excel"){ ;If Excel is active
ControlGet, hwnd, hwnd, , % "EXCEL71", % "- Excel ahk_class XLMAIN" ;identify the hwnd for Word
XL:=ObjectFromWindow(hwnd, OBJID_NATIVEOM)
XL.Selection.Font.Name := "Times New Roman"
XL.Selection.Font.Size := 12
XL:=""
}
return
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment