vba - Importing graphics in order from folder to PowerPoint -


the situation: running macro import graphics folder powerpoint, 4 per slide in custom format, using macro found here.

the issue: order pictures imported not done name of file. how import these photos in order? files named chart 1, chart 2, etc.

the code:

sub insertquadformat()    dim presentation   dim layout   dim slide   dim fso   dim folder   dim file   dim foldername   dim integer    'change folder per needs   foldername = "c\"   = 1    set presentation = application.activepresentation   if presentation.slides.count > 0       presentation.slides.range.delete   end if    set layout = application.activepresentation.slidemaster.customlayouts(3)   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)) = ".png"            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 = 15                   .top = 70                   .height = 460                   .width = 460               end            elseif mod 4 = 2               ' 2,6,10 .... images                set img = slide.shapes.addpicture(foldername + file.name, false, true, 200, 200)               img                   .left = 484                   .top = 70                   .height = 460                   .width = 460               end            elseif mod 4 = 3               ' 3,7,11 .... images                set img = slide.shapes.addpicture(foldername + file.name, false, true, 200, 200)               img                   .left = 15                   .top = 296                   .height = 460                   .width = 460               end           else               ' 4,8,12 .... images                set img = slide.shapes.addpicture(foldername + file.name, false, true, 200, 200)               img                   .left = 484                   .top = 296                   .height = 460                   .width = 460               end           end if       end if       = + 1   next  end sub 

don't work inside "for each file in folder.files" loop. instead, use loop fill array names of files in folder, sort array, loop through array add images.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -