Help with deleting PowerPoint slides with COM

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Help with deleting PowerPoint slides with COM

25 Apr 2016, 20:12

Hi,

Using the code below, pressing F8 or F9 successfully deletes slide 3 of a PowerPoint presentation. As the F9 code shows, a variable can be used for the slide number to delete. However, pressing F10 where the slide number variable comes from parsing a comma-delimited list fails (an error pops up saying that the slide is not found in the Slides collection). Could anyone provide any help on what I'm doing wrong and why deleting the slides by parsing the list, as written below, does not work? Thanks for any help you may be able to provide! (Using AHK 1.1.23.01 ANSI 32 bit on Win 7 64 bit)

Code: Select all

#SingleInstance, Force
Setbatchlines, -1

List_Slides = 2,3,4
Return

F8::
ppt := ComObjCreate("PowerPoint.application")
pt := ppt.ActivePresentation.Slides(3).Delete
Return

F9::
ppt := ComObjCreate("PowerPoint.application")
Slide_To_Delete = 3
pt := ppt.ActivePresentation.Slides(Slide_To_Delete).Delete
Return

F10::
Loop, Parse, List_Slides, `,
	{
	;Msgbox, x_%A_LoopField%_x
	ppt := ComObjCreate("PowerPoint.application")
	pt := ppt.ActivePresentation.Slides(A_LoopField).Delete
	}
Return
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Help with deleting PowerPoint slides with COM

25 Apr 2016, 20:36

It seems A_LoopField is not considered a number.

Code: Select all

#SingleInstance, Force
Setbatchlines, -1
 
List_Slides := "2,3,4"
Return
 
F8::
	ppt := ComObjCreate("PowerPoint.application")
	pt := ppt.ActivePresentation.Slides(3).Delete
Return
 
F9::
	ppt := ComObjCreate("PowerPoint.application")
	Slide_To_Delete := 3
	pt := ppt.ActivePresentation.Slides(Slide_To_Delete).Delete
Return
 
F10::
	ppt := ComObjCreate("PowerPoint.application")
	Loop, Parse, List_Slides, `,
	{
		num := 0
		num += %A_LoopField%
		pt := ppt.ActivePresentation.Slides(num).Delete
	}
Return
Edit: you could use "pt := ppt.ActivePresentation.Slides(Abs(A_LoopField)).Delete" as well.
Please excuse my spelling I am dyslexic.
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: Help with deleting PowerPoint slides with COM

26 Apr 2016, 00:40

Hi Capn Odin,
Thanks for the quick answer. For my use, Abs(A_LoopField) will work best. Thanks a lot for the suggestion, I would have never thought of trying that! Cheers!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 357 guests