Solved

Need More VBA Help with PowerPoint 2010

Posted on 2013-05-21
5
1,252 Views
Last Modified: 2013-05-22
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.
0
Comment
Question by:MrChip2
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
JSRWilson earned 500 total points
ID: 39186604
You cannot make a macro run on CTRL P in PowerPoint

But you just need one macro!

Because pictures can be "pictures" or placeholders containg pictures and PowerPoint measures in POINTS I have included two functions to cope with this

isPicture which returns TRUE or FALSE
and in2Points which converts inches to Points

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
If oshp.Width >= oshp.Height Then 'Landscape
oshp.Width = in2Points(9)
oshp.Top = in2Points(1)
oshp.Left = in2Points(0.5)
Else 'Portrait
oshp.Height = in2Points(6)
oshp.Top = in2Points(1)
oshp.Left = (ActivePresentation.PageSetup.SlideWidth - oshp.Width) / 2
End If
End If
Next oshp
Next osld
End Sub

Function isPicture(oshp As Shape) As Boolean
If oshp.Type = msoPicture Then
isPicture = True
Exit Function
End If
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Then
isPicture = True
Exit Function
End If
End If
End Function

Function in2Points(inVal As Single) As Single
in2Points = inVal * 72
End Function

If this is something you use a lot we could wrap it up into an AddIn that added a ribbon button to run it and was available to all presentations just like all the other buttons. This wouldn't be totally free but would be easy (for us) and not expensive.

johnATSIGNHEREpptalchemy.co.uk

BTW if your landscape images are 4x3 then 9 inches is probably too wide. I would set the height to 6 and centre it personally.
0
 

Author Comment

by:MrChip2
ID: 39186641
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
0
 

Author Comment

by:MrChip2
ID: 39186648
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.
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 39186655
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
0
 

Author Closing Comment

by:MrChip2
ID: 39186690
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!!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This video teaches viewers how to create handouts from their slides and helps them decide how many slides to include per handout.
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now