- I hadn't done anything with COM and PowerPoint before today, but thanks to some example code by HotKeyIt (link lower down), I managed to get a basic example together.
- I've created a PowerPoint_Get function (based on kon's Excel_Get update function) below, it appears to work for me, so hopefully it will work for you. I've also created a PowerPoint_GetViaAcc function, which is more like the original Excel_Get function and which depends on the Acc library.
- I'd been meaning to look at the original and updated Excel_Get functions at some point, so this was a good opportunity to do so. If you compare the two, you can see that kon has done some nice optimisations. One key benefit of the updated Excel_Get function is that it no longer relies on the Acc library functions, it is a stand-alone function.
Code: Select all
;links:
;Excel_Get is AMAZING, could someone make a PowerPoint_Get? - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=44286
;How to use power point VBA in AHK scripts - Ask for Help - AutoHotkey Community
;https://autohotkey.com/board/topic/108576-how-to-use-power-point-vba-in-ahk-scripts/
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
q:: ;PowerPoint - create object
oPt := ComObjCreate("PowerPoint.Application")
oPt.Visible := -1 ;True
oPn := oPt.Presentations.Add()
oPn.Slides.Add(1, 1)
MsgBox, % oPn.Slides.Count
;oPn.Close()
;oPt.Quit()
oPt := oPn := ""
return
w:: ;PowerPoint - latch onto existing object
;oPt := PowerPoint_GetViaAcc()
oPt := PowerPoint_Get()
oPn := oPt.ActivePresentation
MsgBox, % oPn.Slides.Count
oPt := oPn := ""
return
/*
;requires the Acc library
;tested on PowerPoint 2007
PowerPoint_GetViaAcc(vWinTitle:="ahk_class PP12FrameClass", vNum:=1)
{
WinGetClass, vWinClass, % vWinTitle
if (vWinClass == "PP12FrameClass")
{
ControlGet, hCtl, Hwnd,, % "paneClassDC" vNum, % vWinTitle
if !ErrorLevel
{
oWin := Acc_ObjectFromWindow(hCtl, -16)
if (ComObjType(oWin) = 9)
while !oPt
try oPt := oWin.Application
catch e
if (SubStr(e.Message, 1, 10) = "0x80010001")
ControlSend, % "paneClassDC" vNum, {Esc}, % vWinTitle
else
return "Error accessing the application object."
}
}
return oPt
}
*/
;tested on PowerPoint 2007
PowerPoint_Get(vWinTitle:="ahk_class PP12FrameClass", vNum:=1)
{
static h := DllCall("kernel32\LoadLibrary", Str,"oleacc", Ptr)
WinGetClass, vWinClass, % vWinTitle
if !(vWinClass == "PP12FrameClass")
return "Window class mismatch."
ControlGet, hCtl, Hwnd,, % "paneClassDC" vNum, % vWinTitle
if ErrorLevel
return "Error accessing the control hWnd."
VarSetCapacity(IID_IDispatch, 16)
NumPut(0x46000000000000C0, NumPut(0x0000000000020400, IID_IDispatch, "Int64"), "Int64")
if !(DllCall("oleacc\AccessibleObjectFromWindow", Ptr,hCtl, UInt,-16, Ptr,&IID_IDispatch, PtrP,pAcc) = 0)
return "Error calling AccessibleObjectFromWindow."
oWin := ComObject(9, pAcc, 1)
if !(ComObjType(oWin) = 9)
return "Error wrapping the window object."
Loop
try return oWin.Application
catch e
if (SubStr(e.message, 1, 10) = "0x80010001")
ControlSend, % "paneClassDC" vNum, {Esc}, % vWinTitle
else
return "Error accessing the application object."
}
;==================================================