MS Powerpoint 2007 & VBA Macro: How to insert a picture on a slide and change picture properties?

A macro code is needed in MS Powerpoint 2007 VBA which achieves the followings.

When a new & empty Powerpoint file is open on its first slide:
1. Finds the list of pictures and figures (extension .JPG or .BMP) in a directory.

2. Inserts each of them on slides.

--- if a picture is vertically oriented (by checking height > width), then two vertical pictures on a slide one at upper right corner, one at the left.

--- if horizontally oriented, then two pictures on a slide one under the other.

3. Resizes pictures to fit into 400 x 400 pixels square.

4. Writes the filename as a caption below each picture inside a textbox.

Who is Participating?
TAI-Connect With a Mentor Author Commented:

I could not manage to split the question. So decided to provide the missing part of the question below.

The below code attaches a text box onto a newly created slide. I wrote in this fashion to be a little compatible with the first part of the solution as GlennaShaw suggested:

Sub CreateCaption()

Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oCaption As Shape

strPath = "C:\"
strFileSpec = "*.*"

strTemp = Dir(strPath & strFileSpec)

Do While strTemp <> ""
    Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)

    Set oCaption = oSld.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 150, 100, 20)
    With oCaption
        .TextFrame.WordWrap = msoFalse
        .TextFrame.AutoSize = ppAutoSizeShapeToFitText
        .TextFrame.TextRange.Text = strTemp
    End With
    strTemp = Dir

End Sub

All the best,
Use the Macro Recorder under Tools Macro

Good Luck!

Jeffrey CoachmanMIS LiasonCommented:

You have actually asked for quite a bit here.
In fact, you have actually asked four separate questions.
(You are only allowed one question per post, so each of you requests really needs to be its own separate, new question)

What you have asked for here amounts to a "complete project".
This is not a single question requiring a straightforward answer.

This will also not be one simple macro.

If you don't get many hits on this, I suggest that you click the "Request Attention" button and ask for help with breaking this into separate questions.

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

GlennaShawConnect With a Mentor Commented:
Check out:

You'll need to modify the code a bit.

If you're not a programmer, I recommend getting the Image Import Wizard add-in.
BTW, Office 2007 no longer has the macro recorder.
TAI-Author Commented:

Thank you JeffCoachman:
The point in your recommendation is very important and it will be considered for future questions.

Thank you GlennaShaw:
The code you referred in the link works very well. However, it does not provide an answer for 2nd and 4th items. So I gave partial points to you.
Well, I have manipulated it towards my needs.

As Jeff recommended I will split the 4th part of the question...

All the best,
Jeffrey CoachmanMIS LiasonCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.