So, a few months ago, so code I had for Excel stopped working after my company changed some security settings. I despaired of being able to control Excel with AHK again, when I came across "Excel_Get". It is wonderful! It saved my script, and saved me and my company hundreds of hours.
However, now I am being asked to automate a process involving PowerPoint. And I am getting the same error messages. Has anyone created a "PowerPoint_Get" script?
Excel_Get is AMAZING, could someone make a PowerPoint_Get?
Re: Excel_Get is AMAZING, could someone make a PowerPoint_Get?
- I could give this a try via Acc using the same techniques that Excel_Get uses. I don't know if it will work for sure.
- Could you provide some very basic working PowerPoint code in AutoHotkey, for testing purposes. Thanks.
- Links:
[new function that doesn't require Acc]
Excel_Get - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
MS-Office-COM-Basics/Excel_Get.ahk at master · ahkon/MS-Office-COM-Basics · GitHub
https://github.com/ahkon/MS-Office-COM- ... el_Get.ahk
[original function that requires Acc]
AHK failure with Excel_Get () - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/8833 ... /?p=560328
excel and com? - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/7394 ... ntry469769
- Could you provide some very basic working PowerPoint code in AutoHotkey, for testing purposes. Thanks.
- Links:
[new function that doesn't require Acc]
Excel_Get - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
MS-Office-COM-Basics/Excel_Get.ahk at master · ahkon/MS-Office-COM-Basics · GitHub
https://github.com/ahkon/MS-Office-COM- ... el_Get.ahk
[original function that requires Acc]
AHK failure with Excel_Get () - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/8833 ... /?p=560328
excel and com? - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/7394 ... ntry469769
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Excel_Get is AMAZING, could someone make a PowerPoint_Get?
My code is VERY basic. Merely doing
creates "Error x080080005 Server execution failed".
I get the same error message when I try that with
However,
works.
So far as I can tell, this is because of the various security/dummy proofing things that the IT department has done to the company computers. I am not sure which step of Excel_Get() works, but at least one of them does. I am just hoping for something in PowerPoint that does the same thing.
Code: Select all
oPPT := ComObjCreate("PowerPoint.Application")
I get the same error message when I try that with
Code: Select all
oWkbk := ComObjCreate("Excel.Application")
Code: Select all
oWkbk := Excel_Get()
So far as I can tell, this is because of the various security/dummy proofing things that the IT department has done to the company computers. I am not sure which step of Excel_Get() works, but at least one of them does. I am just hoping for something in PowerPoint that does the same thing.
Re: Excel_Get is AMAZING, could someone make a PowerPoint_Get?
- 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.
- 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."
}
;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Excel_Get is AMAZING, could someone make a PowerPoint_Get?
I've updated the function to handle more versions of PowerPoint.
Further links that discuss PowerPoint_Get and variant functions:
Excel_Get - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
Ppt_Get (like Excel_Get or Word_Get) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=45822
Code: Select all
;tested on PowerPoint 2007
PowerPoint_Get(vWinTitle:="ahk_class PP..?FrameClass", vNum:=1)
{
static h := DllCall("kernel32\LoadLibrary", Str,"oleacc", Ptr)
vTMM := A_TitleMatchMode
if (vWinTitle = "ahk_class PP..?FrameClass")
SetTitleMatchMode, RegEx
hWnd := WinExist(vWinTitle)
WinGetClass, vWinClass, % "ahk_id " hWnd
SetTitleMatchMode, % vTMM
if !(vWinClass ~= "PP..?FrameClass")
return "Window class mismatch."
ControlGet, hCtl, Hwnd,, % (vCtlClass := "mdiClass") vNum, % "ahk_id " hWnd
if !hCtl
ControlGet, hCtl, Hwnd,, % (vCtlClass := "paneClassDC") vNum, % "ahk_id " hWnd
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, % vCtlClass vNum, {Esc}, % vWinTitle
else
return "Error accessing the application object."
}
Excel_Get - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
Ppt_Get (like Excel_Get or Word_Get) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=45822
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Excel_Get is AMAZING, could someone make a PowerPoint_Get?
Working on PowerPoint 2016 and PowerPoint 2013 also. Will test on 2010 in VM later.
Good show!
Bravo! Very clever indeed.
Regards,
burque505
Good show!
Bravo! Very clever indeed.
Regards,
burque505
Who is online
Users browsing this forum: jeves and 156 guests