Wednesday, 15 January 2014

vba - importing images and placing them in an array in powerpoint -



vba - importing images and placing them in an array in powerpoint -

i'm new powerpoint vba programming. i'm struck problem, have macro script takes path folder images there , places 1 image per slide. want macro script prompt user whether place 4 or 6 or 8 images in slide. output i'm expecting below:

i know can done "insert photoalbum" problem has alternative 4 images per slide. reason i'm writing macro. code used:

sub createpictureslideshow() dim presentation dim layout dim slide dim fso dim folder dim file dim foldername ' set point @ folder wish import jpgs ' note: create sure ends backslash \ foldername = "c:\users\hamanda\desktop\b2_images\" ' delete slides , setup variables set presentation = application.activepresentation if presentation.slides.count > 0 presentation.slides.range.delete end if set layout = application.activepresentation.slidemaster.customlayouts(1) set fso = createobject("scripting.filesystemobject") ' retrieve folder's file listing , process each file set folder = fso.getfolder(foldername) each file in folder.files ' filter process jpg images if lcase(mid(file.name, len(file.name) - 3, 4)) = ".png" ' create new slide , delete pre-existing contents set slide = presentation.slides.addslide(presentation.slides.count + 1, layout) while slide.shapes.count > 0 slide.shapes(1).delete wend ' add together image slide.shapes.addpicture foldername + file.name, false, true, 10, 10 ' optional: create textbox filename on slide reference ' dim textbox ' set textbox = slide.shapes.addtextbox(msotextorientationhorizontal, 10, 10, 200, 200) ' textbox.textframe.textrange.text = file.name end if next end sub

so how can modify inserting 4 or 6 or 8 images in slide help me this

tested

funtion mod

and properties of shape left,top,height,width help solution problem.

see comments in code improve understanding :). allow me know if need farther help .

below code insert 4 images in single slide.. if insert more images have insert elseif , modvalue

sub createpictureslideshow() dim presentation dim layout dim slide dim fso dim folder dim file dim foldername dim integer 'change folder per needs foldername = "c:\temp\c\" = 1 set presentation = application.activepresentation if presentation.slides.count > 0 presentation.slides.range.delete end if set layout = application.activepresentation.slidemaster.customlayouts(1) set fso = createobject("scripting.filesystemobject") set folder = fso.getfolder(foldername) ' loop though each image in folder each file in folder.files if lcase(mid(file.name, len(file.name) - 3, 4)) = ".jpg" if mod 4 = 1 ' 1,5,9 .... images set slide = presentation.slides.addslide(presentation.slides.count + 1, layout) while slide.shapes.count > 0 slide.shapes(1).delete wend set img = slide.shapes.addpicture(foldername + file.name, false, true, 200, 200) img .left = 0 .top = 0 .height = 300 .width = 300 end elseif mod 4 = 2 ' 2,6,10 .... images set img = slide.shapes.addpicture(foldername + file.name, false, true, 200, 200) img .left = 301 .top = 0 .height = 300 .width = 300 end elseif mod 4 = 3 ' 3,7,11 .... images set img = slide.shapes.addpicture(foldername + file.name, false, true, 200, 200) img .left = 0 .top = 301 .height = 250 .width = 250 end else ' 4,8,12 .... images set img = slide.shapes.addpicture(foldername + file.name, false, true, 200, 200) img .left = 300 .top = 301 .height = 250 .width = 250 end end if end if = + 1 next end sub

vba powerpoint-vba

No comments:

Post a Comment