Link to home
Start Free TrialLog in
Avatar of jwilk8284
jwilk8284

asked on

Powerpoint - Inserting Many Photos

I need help finding a way to make inserting many photos into a powerpoint presentation more efficient.  How would I take a batch of digital images (usually 50 to 300) and put each image on its own slide?  And also at a particular height and width?  Is there a macro available for this?  If not, can you get me started?  I don't know Visual Basic programming, so if there is code involved please help.  It's repetitive, boring and cumbersome (the computer should be doing the work, not me) to do this one picture at a time, there must be a way of taking the whole batch of images and doing a batch entry.  I am not concerned about the titles - those I need to enter one at a time - I am just talking about inserting the photo images, one to a slide, and if possible also getting them to the right size.
Avatar of jwilk8284
jwilk8284

ASKER

Adjusted points to 400
Strange that nobody tackled this one. As you can record the "insert picture from file", it should be feasible to make a loop using VBA.

Therefore:

a) Are you still out there ?

b) Would it be possible to have a
dedicated directory containing only these pictures which will be included ?

c) As it would be my first Powerpoint macro: Is time crucial ?

d) Regarding picture type, directories etc.: What is fixed what must be user input ?
cri,
I've checked now and then.  Glad you responded.  
Yes, I usually put the pictures in a dedicated directory on my local hard drive.  Time is not that crucial in this case.  What I do is insert each jpg picture into its own slide, in a standard template I have set up.  Then, I usually have to re-size each photo manually (click and drag) to fit its slide.  The pictures from the digital camera I use are usually too big, so I bring them down to a height of 6 and a width of 8.  Finally, I add a title.  Not sure if I answered all of your questions.  Let me know if you need anything else.  Thank you.
jwilk8284
Ok I will make a pass at it, but it will take a week or so.

I do not understand your comment "...I checked now and then..." Don't you have e-mail notification, it is below the comment editing window, checked ?

Did you ever record or at least use a macro ? Are you interested in this ? Its fairly easy and I consider it as the entry step to making your life easier by automating your repetitive tasks. I mention it here because if you would record and paste here what you do when importing, I could make a loop and insert the dialog boxes where you could make the necessary input.
cri,

After reading your comment, I checked my profile and found a typo in the e-mail address.  

About recording a macro, I have tried this before once or twice - very inexperienced.  However, I tried to record a macro.  See below.  

Sub InsertPics()
'
' Macro recorded 3/28/00 by Jim Wilkinson
'
    ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="C:\SitePics\002Mvc-416l.jpg", LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=-23, Top:=-17, Width:=768, Height:=576).Select
    With ActiveWindow.Selection.ShapeRange
        .Height = 431.88
        .Width = 575.88
        .Left = 71.88
        .Top = 53.88
    End With
    ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select
    ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
    With ActiveWindow.Selection.TextRange
        .Text = "Approaching N-31"
        With .Font
            .Name = "Times New Roman"
            .Size = 28
            .Bold = msoFalse
            .Italic = msoFalse
            .Underline = msoFalse
            .Shadow = msoFalse
            .Emboss = msoFalse
            .BaselineOffset = 0
            .AutoRotateNumbers = msoTrue
            .Color.SchemeColor = ppTitle
        End With
    End With
    ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=8, Layout:=ppLayoutTitleOnly).SlideIndex
End Sub

When I get back from shooting pictures, I upload all images from the digital camera into a folder called "C:\SitePics".  (note: eventually, I move the images from this folder to accomodate the next batch of images).  The file names are generated automatically by the digital camera, an example is "001Mvc-415l.jpg".  I always check the "Link to File" and "Save with Document" boxes when inserting.  Then I re-size the image.  Then add the title in the Title Text Box.  After that, add a new slide and repeat the process with the next image - by next image, I mean the next one in chronological order.  That doesn't show up in the above macro because I'm not sure how to make that happen.

jwilk8284  
I will post the first version in about 8-10 hours. Should you see this comment first: Is the caption writen in the Title of a "Title Only" layout or is it a regular textbox ?

Reason I am asking is that I am battling somewhat with the %*"&%! lame brained way of Microsoft to continuously assign numbers to shapes per Powerpoint start. In Excel I could assign name to them, but I am not there yet. Probably I will have to send you a raw cut version to determine the room for improvement.  
not send, post
Paste everything below the demarcation line into the same module where you have the recorded macro. Make sure you have some pics in the same directory.

More after the break, meaning feedback from you, especially regarding your needs/wishes regarding room for improvement, see header macro (with a 400 pointer you deserve it)


'xxxxDemarcationUsedToInforceFrameWidthExpertsExchange**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Sub InsertAllPics_v1()

' Inserts all files into a Powerpoint presentation in the _same_ directory
'
' Room for improvement:
'  - General finetuning as size and location of title frame
'  - Is first inserted picture = last slide acceptable ? Considerably easier to handle
'  - Would separate directories for Powerpoint and pictures be an advantage ?
'  - Include filename in footer in fine print ?
'  - Input dialog to edit and insert picture title for each slide ?
'  - Delete last slide as empty

   'Initialisation
   
   ' Declare all variables
   Dim MyPics As String, SlideNumber As Integer
   Dim InpTxt As String, InpPath As String
     
   ' Define input dialog text
   InpTxt = "Will import all indicated pictures. Accept default or modify:"
   ' Get user confirmation/modification of picture directory/extension
   InpPath = InputBox(InpTxt, "InsertAllPics_v1", "C:\SitePics\*.jpg")
   
   ' Returns _first_ file *.jpg found in indicated directory
   MyPics = Dir(InpPath)
   
   ' Ensure slideview as macro can not run in slide sorter view
   ActiveWindow.ViewType = ppViewSlide
     
   ' Start the importing
   Do While MyPics <> ""
           
      ' Add new slide at the _beginning_ of the presentation
      ' Avoids messing with counter
      ActivePresentation.Slides.Add 1, ppLayoutTitleOnly
      'and go there
      ActiveWindow.View.GotoSlide Index:=1
           
      ' Add pic with values posted in E-E (which overlaps with tile)
      ActivePresentation.Slides(1).Shapes.AddPicture(FileName:=MyPics, _
             LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, _
             Left:=72, Top:=54, Width:=576, Height:=432).Select
           
      ' If scaling not needed, delete this section
      With ActiveWindow.Selection.ShapeRange
         .ScaleWidth 0.85, msoFalse, msoScaleFromBottomRight
         .ScaleHeight 0.85, msoFalse, msoScaleFromBottomRight
         .IncrementLeft -43 ' calculated as -(1 - 0.85)*572/2
         .IncrementTop 20
      End With
         
      ' Using Titles, a textbox might be better solution
      With ActivePresentation.Slides(1).Shapes.Title.TextFrame.TextRange
         .Characters(Start:=1, Length:=0).Select
         .Text = MyPics 'Filename as placeholder for later editing
             With .Font
                .Name = "Times New Roman"
                .Size = 28
                .Bold = msoFalse
                .Italic = msoFalse
                .Underline = msoFalse
                .Shadow = msoFalse
                .Emboss = msoFalse
                .BaselineOffset = 0
                .AutoRotateNumbers = msoTrue
                .Color.SchemeColor = ppTitle
             End With
      End With
     
      'Call Dir again w/o arguments to return next (DOS) indicated file
      MyPics = Dir
   Loop
     
   ' For visual check and eventual sorting
   ActiveWindow.ViewType = ppViewSlideSorter

End Sub
cri,

The macro bogged down early. So I didn't get to fully evaluate your solution.  

The powerpoint presentation I ran is in the "D:\ENGR_RVWS" folder.  The dialog box for the directory came up fine - I pressed the OK button to accept the default directory "C:\SitePics\*jpg" since that is where I keep my photos.  Then a Microsoft Visual Basic box appeared with the following message: "Run-time error' -2147188160 (80048240)': Shapes (unknown member): Out of memory error."  

To answer your earlier question - yes, the caption is written in the Title of a "Title Only" layout.

Other questions you have:

"Is first inserted picture = last slide acceptable ? Considerably easier to handle"  As I stated before, chronological order is best.  If you are saying reverse order is much easier - that would be fine if there was a quick way to re-sort but I don't see that Powerpoint provides a way to do that.  

"Would separate directories for Powerpoint and pictures be an advantage ?"  Not sure what you mean, I thought that's what we were doing anyway.  If I provide the following information maybe your question will be answered.  On my machine, the Powerpoint application is in C:\MSOffice\Office folder, photos are in C:\SitePics folder, and each presentation has its own project folder on the D:\ drive (sub-folders to the "D:\ENGR_RVWS" folder).

"Include filename in footer in fine print ? "  Not necessary.

"Input dialog to edit and insert picture title for each slide ? "  That's a great idea, I would appreciate that.





For testing purposes please put your Powerpoint file in the same directory as a _test_ set of pictures, see header of macro. Reason I did not made it yet is that (presently) I think there will be a need to have 2 input dialogs: One for the directory and one for the file extension. Whereas you could say skip the extension (as _always_ *.jpg) I must point out that you can only have the pictures you want to import in the directory. Either you move the previous out or I give you the feature to address another directory (which should exist, I must draw the line somewhere...)

As for the title edit dialog: I must think this over, perhaps I can not get the view refresh working and/or the speed of the current solution which would allow this feature is too low. Explanation: I am toying in formatting and sizing in one go, using ranges, time to think object oriented instead of procedurally. But I will only do this if it is too slow, I am not this kind of purist. Please inform how long it takes to import a medium to large batch.
Regarding you moving the pictures out of c:\sitepics

a) Did you never had any troubles when editing/modifying the presentation afterwards  ? Reason is that you, besides embeding, link the pictures, i.e. the reference will not be correct after the move.

b) Why do you embed _and_ link ? Do you distribute the presentation and still want to keep the "original" pictures ?
cri,

OK, the photos imported into the presentation, in reverse order, with the photo's filename as the title.  That's a good start!

In my template, there are four introductory slides. If you can make the insertions begin on slide 5, that would be great.  If not, I can manually move those four introductory slides back to the beginning manually.

The photos came in at a height of 5.1 inches and a width of 6.8 inches.  Will you make that 6.0x8.0?

The photos came in at 1.6 inches horizontal and 1.93 inches vertical relative to the top left corner.  Will you make that 1.08 inches horizontal and 0.67 inches vertical?

I hope you can solve the problem with respect to order.  Your current macro is better than what I have now, but I wouldn't look forward to manually putting the slides in the correct order.  It would negate some of the time gained by the automatic insertion of the photos.

The dialog box that comes up has "C:\SitePics\*jpg"  as the default.  Is that the only directory the macro will work with?  I tried to put the presentation file into a different directory with a bunch of photos, and change the directory name manually in the dialog box (BTW, if it is possible to use a different directory, will you build in a file find box? - it's a pain to type out long path names manually) and it didn't seem to work.  

Regarding input of the titles, I have thought about that further and think that this can be done manually, outside of the macro.  Really, the big thing is to get all the photos situated in the right place, the right size, and in order.  I really loved seeing all those photos pop into the presentation automatically, so quickly!  What a timesaver.  

It looks like you are not far away from a final solution.  What you have right now, is fine, with the exception of the order and the few minor items listed above.  Will you please look at those improvements?

cri,

Perhaps I don't understand the Embed and Link concepts.  What I am after is this.  I would like to distribute the presentation after it is done, by placing it out on our LAN server.  I want it to be a standalone file, and not have to put the photos out on the server along with the presentation file.  Is it unnecessary to Link?
cri,

Perhaps I don't understand the Embed and Link concepts.  What I am after is this.  I would like to distribute the presentation after it is done, by placing it out on our LAN server.  I want it to be a standalone file, and not have to put the photos out on the server along with the presentation file.  Is it unnecessary to Link?
I will tackle this to the end, but it can take up to a week, I am quite busy and this is my first Powerpoint macro.

Now for the details:

a) I probably will be able to fix the order.

b) Starting from slide 5 should be feasible. Is it correct that you have a template for this ?

c) I scaled it because I have A4 paper and the picture overlapped with my _default_ Title. What paper size and margins do you have in your presentation ? Try with inactivating the scaling section (precede each line with a ').

d) Strange that it did not work with another directory. Did you start the presentation there or did you make a save as only ? Will keep an eye on this. You sure you put ..\*.jpg and not ..\*jpg as you wrote ?

e) Passing return from File Open dialog to my input box...Uhhh... Will see, but I do not promise anything.

Picture the link as a tight "rope" to an external file and the embed as tucking it into the presentation. Linking is good if the files will be updated/revised as this happens with reports etc., but to distribute they are a pain. If you are sure your pictures are not going to be edited, embeding is what you need. Whether you keep the pictures is up to you, I rembember that *.jpg inserted into an Office application are converted to *.emf (or whatever) and get much bigger.
cri,

one week - fine

a) great.

b) yes, I have a template.

c) I will check this when I get back to work on Monday.  What do you mean by "Try with inactivating the scaling section (precede each line with a ')?"

d) I will try this again, on Monday, to be sure, and will tell you exactly what it is doing.

e) that is fine.

Thanks for the explanation on "link" and "embed".

I'll get back to you on Monday.  
Regarding c) You can inactivate code by preceding a ' before each line, the VBA interpreter will treat as comment and it will be in red in the VBA editor. Is better than to delete, perhaps we will need it. Afterwards it should look like this:

' If scaling not needed, delete this section
      ' With ActiveWindow.Selection.ShapeRange
        ' .ScaleWidth 0.85, msoFalse, msoScaleFromBottomRight
        ' .ScaleHeight 0.85, msoFalse, msoScaleFromBottomRight
        ' .IncrementLeft -43 ' calculated as -(1 - 0.85)*572/2
        ' .IncrementTop 20
    '  End With
           
Additionally: As a.m. what paper size and margins to you have ?      
cri,

In "Page Setup", slides are sized for "On Screen Show", width =10 inches, height = 7.5 inches, Landscape.

Thanks, I did not forget your question.
cri,

Followup to earlier discussion:

c) inactivated the scaling section, and the photos came in much better this time.  Good suggestion.

d) tried putting the presentation file and photos in a different directory, ran the macro and it brought the photos in, so disregard previous comment and I apologize for any confusion.

 
ASKER CERTIFIED SOLUTION
Avatar of cri
cri
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cri,

Great job.  I like what you have done with this macro.  400 points is yours as well as my appreciation for taking on the problem and getting it solved.
cri has been pleasant to deal with.
Thanks. You are welcome.

This was a nice exercise on how to get started with VBA:

a) Believe that there must be a way better than original Microsoft

b) Record macro.

c) Improve code:
- Make sure VBA help is installed, if I remember this correctly you must run Office setup again as not in default setup.
- This URL is handy to bookmark for later consultations (provided you have a cheap ISP/telecom or tons of printer paper)
http://msdn.microsoft.com/library/officedev/office97/web/fulltoc.htm

d) Use E-E if you get stuck. Powerpoint support is astonishingly low, but for Excel the expert competition is fierce and the code usually is good to excellent.
This works well, but I have an issue along these lines.  I have scanned a number of old family photos.  Due to the photos being damaged, irregularly sized, or stuck in scrapbooks where it was hard to capture the original size - I cannot just assign a value to width and height.  In the above, you use width of 10 and height of 7.  These are multiplied by 72.   If I do that, my pictures are distorted in size.  

How can I use this macro to insert the photos but use the original size of the photo I scanned, or if you are really good, how can I set the height not greater than 7 and proportion the width, or set width not greater than 10 and proportion height?
It should not be difficult to improve this code, whereas I am not "really good", I am better than 5 years ago. At least regarding VBA....

However before I do this:
a) If you already solved it, please tell me so.
b) Regarding the photos. I did just a similar task. I cropped/resampled/resized them, as most graphic software are able. But granted cutting the pictures to keep the proportions is not always a good solution.  
I have resolved my isue.   I asked this question (or one very similar to it) on my own thread.   See
https://www.experts-exchange.com/questions/21500822/Inserting-many-photos-into-PowerPoint-using-original-photo-size.html

In it, I can import any size picture and have it resized so one dimension fits the screen while the other is proportioned equally.  Whichever fits better, height or width, the other dimension is modified proportionately.   This works to increase or decrease the size to fit.  Then, it centers the photo in the slide.  I received some good help and then improvised to complete the rest.  I posted the final product on this link.

Thanks for the help!