checkbox - Select certain slides by check boxes in Power Point VBA -
i need able create new .ppt
(powerpoint presentation) selected slides in original .ppt
. following macro take whatever slides have selected , copy them new .ppt
. i've found following nice code of work.
private sub nytppt_click() 'purpose: copies selected slides , pastes them brand new presentation file 'source: www.thespreadsheetguru.com dim newppt presentation dim oldppt presentation dim selected_slds sliderange dim old_sld slide dim new_sld slide dim x long, y long dim myarray() long dim sorttest boolean 'set variable active presentation set oldppt = activepresentation 'set variable equal selected slides in active presentation set selected_slds = activewindow.selection.sliderange 'sort selected slides via slideindex 'fill array slideindex numbers redim myarray(1 selected_slds.count) y = lbound(myarray) ubound(myarray) myarray(y) = selected_slds(y).slideindex next y 'sort slideindex array sorttest = false y = lbound(myarray) ubound(myarray) - 1 if myarray(y) > myarray(y + 1) swap = myarray(y) myarray(y) = myarray(y + 1) myarray(y + 1) = swap sorttest = true end if next y loop until not sorttest 'set variable equal selected slides in active presentation (in numerical order) set selected_slds = oldppt.slides.range(myarray) 'create brand new powerpoint presentation set newppt = presentations.add 'align page setup newppt.pagesetup.slideheight = oldppt.pagesetup.slideheight newppt.pagesetup.slideorientation = oldppt.pagesetup.slideorientation newppt.pagesetup.slidesize = oldppt.pagesetup.slidesize newppt.pagesetup.slidewidth = oldppt.pagesetup.slidewidth 'loop through slides in sliderange x = 1 selected_slds.count 'set variable specific slide set old_sld = selected_slds(x) 'copy old slide yy = old_sld.slideindex old_sld.copy 'paste slide in new powerpoint newppt.slides.paste set new_sld = application.activewindow.view.slide 'bring on slides design new_sld.design = old_sld.design 'bring on slides custom color formatting new_sld.colorscheme = old_sld.colorscheme 'bring on whether or not slide follows master slide layout (true/false) new_sld.followmasterbackground = old_sld.followmasterbackground next x end sub
what need do, select slides copy - based on check boxes. so, example if select check box 1 = true, create slides 1, 2 , 3. or if select check box 2 = true, select slide 3, 4, 5 , 6. , so, if selected both boxes create slides = 1, 2, 3, 4, 5, 6. leaving out duplicates.
i've tried lot, including this:
private sub checkbox1_click() if checkbox1.value = true activepresentation.slides.range(array(1, 2, 3)).select else msgbox "nothing" end if end sub private sub checkbox2_click() if checkbox2.value = true activepresentation.slides.range(array(3, 4, 5, 6)).select else msgbox "nothing" end if end sub
i error: slide (unknown member) : invalid request. view not support selection.
i not sure how work? appreciated, i'am new vba coding.
all credit code goes to. http://www.thespreadsheetguru.com/the-code-vault/2014/4/3/copy-selected-slides-into-new-powerpoint-presentation
you can switch view enabled slides selected follows:
activewindow.viewtype = ppviewslidesorter
for reason, slides aren't selected in normal view!
but selecting things in powerpoint brings own challenges (as seen view type) , don't need select them in order copy , paste them per example:
with activepresentation.slides .range(array(1, 2)).copy .paste end
this simplify code don't need manage windows , views.
Comments
Post a Comment