Link to home
Start Free TrialLog in
Avatar of Chip Levinson
Chip LevinsonFlag for United States of America

asked on

Need More VBA Help with PowerPoint 2010

Hello,

Recently JSRWilson helped me out with some VBA code for PowerPoint 2010.  I have another very time consuming, repetitive task that would greatly benefit from a macro.  The problem?  I have no VBA experience.  I sure do miss the macro record feature....

Here is what I want to do.  I have a 500 slide presentation.  Each slide has a title and then a single JPEG image on it.  The JPEG images have varying dimensions and contain a mix of text and graphics.  I would like to re-size all of the images to the maximum size w/o distorting them.  Then I want to position them consistently in the same place on the slide.

For example, here are some size and position numbers on a few slides: (Note, all pictures have locked aspect ratios relative to original picture size)

Slide #1:
Height = 5.2",
Width = 6.73",
Scale = 100%, 100%,
Horizontal Position 1.64" from Top Left Corner
Vertical Position 1.8" from Top Left Corner

Slide #2
Height = 3.65",
Width = 9.0",
Scale = 129%, 129%,
Horizontal Position 0.5" from Top Left Corner
Vertical Position 2.58" from Top Left Corner

Slide #3
Height = 5.2",
Width = 4.02",
Scale = 100%, 100%,
Horizontal Position 2.99" from Top Left Corner
Vertical Position 1.8" from Top Left Corner

About 70% of the pictures are in landscape mode - meaning their width is greater than their height (slides 1 and 2).  The rest are in portrait modes where their height is greater than their width.

To do this efficiently, I think I need two macros.  One for portrait and one for landscape.  They should be set up so I press Control-L for landscape and Control-P for portrait.  Then I can toggle thru each slide and use the appropriate macro.

Here is what I think I want to change all of the landscape slides to using Control-L:

Desired Size and Position for Landscape
Height = adjusted automatically to maintain aspect ratio,
Width = 9.0" fixed,
Scale = this will adjust automatically, but will be equal like 110%, 110%,
Horizontal Position 0.5" from Top Left Corner
Vertical Position 1.0" from Top Left Corner

Here is what I think I want to change all of the portrait slides to using Control-P:

Desired Size and Position for Portrait
Height = 6.0" fixed,  
Width = adjusted automatically to maintain aspect ratio,
Scale = this will adjust automatically, but will be equal like 110%, 110%,
Horizontal Position centered on page (0" from Center)
Vertical Position 1.0" from Top Left Corner

Thank you so much in advance for your help with this!  Please let me know if you have any questions.  I can really use an answer in the next 12 hours, if possible.
ASKER CERTIFIED SOLUTION
Avatar of John Wilson
John Wilson
Flag of United Kingdom of Great Britain and Northern Ireland 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
Avatar of Chip Levinson

ASKER

Hi John,

I was just about to sign off (it is midnight) when your response posted.  Not sure what time it is for you, but thank you for replying so quickly.  This is the first time I needed to do something like this.  There is a chance I will need to do it again in 4-6 months.  If that happens, I would be curious about the add-in option.

For now, I am not sure how to implement your solution.  Do I create a single macro and copy everything starting at:

Sub fixImages()

and ending at
End Function
Wow - just did it and it worked!!  You were right I think my dimensions were too big.  Many of the landscape images are now so tall that they extend below the page.  I will do a quick check to see if there are too many to crop manually.  I'll let you know in a few minutes.
As I said I would consider using the same code for portrait and landscape.

Sub fixImages()
Dim osld As Slide
Dim oshp As Shape

For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If isPicture(oshp) Then
oshp.Height = in2Points(6)
oshp.Top = in2Points(1)
oshp.Left = (ActivePresentation.PageSetup.SlideWidth - oshp.Width) / 2
End If
Next oshp
Next osld
End Sub

You will need the (same) functions code too

An alternative would be to add code to crop to 1 inch from the bottom of the slide
John
A++++
I noticed that a decent percentage of the landscape images were too big, so I changed a couple of numbers:

oshp.Width = in2Points(9 ==> 7.5)
oshp.Top = in2Points(1)
oshp.Left = in2Points(0.5 ==> 1.5)

Now almost all the images are formatted as I like.  Thank you again!!