Solved

How do I resize images using vba code (powerpoint 2010) so they are center scaled?

Posted on 2015-01-18
7
419 Views
Last Modified: 2015-01-28
I've written vba code to reduce the width of all images in a deck by 25%. But they default to reducing these images by the right side. How can I incorporate into my code that the images scale back 25% from their center and not the right side. I know there is a vba term ScaleFromMiddle but don't know how to incorporate it into my code.
Thank you.

Sub Scale()
Dim Sl As Slide
Dim Sh As Shape
For Each Sl In ActivePresentation.Slides
    For Each Sh In Sl.Shapes
        Sh.LockAspectRatio = False
    Next
Next
Dim oshp As Shape
Dim osld As Slide
Dim dblscaleamount As Double

dblscaleamount = 0.75
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = msoPicture Or _
   oshp.Type = msoChart Or _
   oshp.Type = msoTable Or _
   oshp.Type = msoAutoShape Or _
   oshp.Type = msoGroup Then
oshp.width = oshp.width * dblscaleamount
oshp.Height = oshp.Height
End If
Next oshp
Next osld
End Sub
0
Comment
Question by:Cadberry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 40556959
0
 
LVL 51

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 167 total points
ID: 40557082
Hi,

pls try

oshp.ScaleWidth dblscaleamount, msoFalse, msoScaleFromMiddle

Regards
0
 
LVL 23

Assisted Solution

by:JSRWilson
JSRWilson earned 167 total points
ID: 40557121
Just a slight addition to Rgonzo's good code

With oshp
    .LockAspectRatio = msoTrue
    .ScaleWidth dblscaleamount, msoFalse, msoScaleFromMiddle
End With

For images LockAspectRation True is the default but not for shapes where the default is False

Pedantic point Factor is a Single not a Double
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 12

Accepted Solution

by:
Jamie Garroch earned 166 total points
ID: 40557241
In addition, I get a compile error with the procedure name so putting it all together:

Option Explicit

' Scale all shapes from their centres in all slides in the current presenation
Sub ScaleShapes()
  Dim oSld As Slide
  Dim oShp As Shape
  Dim sScale As Single
  
  sScale = 0.75
  
  For Each oSld In ActivePresentation.Slides
    For Each oShp In oSld.Shapes
      With oShp
        If .Type = msoPicture Or _
           .Type = msoChart Or _
           .Type = msoTable Or _
           .Type = msoAutoShape Or _
           .Type = msoGroup Then
              .LockAspectRatio = msoTrue
              .ScaleWidth sScale, msoFalse, msoScaleFromMiddle
        End If
      End With
    Next
  Next
End Sub

Open in new window

0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 40557481
Yep Scale is a vba reserved word like Print, Byte, Dim etc.

I have tries several times to get a full list but it doesn't seem to exist.
0
 
LVL 12

Expert Comment

by:Jamie Garroch
ID: 40557488
Glad it's not just me JSRWilson!
0
 

Author Closing Comment

by:Cadberry
ID: 40576671
Thank you all! These are fantastic solutions.
I was being stubborn and trying to figure out how to have IncrementLeft = 12.5% of the image width as an alternative to ScaleFromMiddle but finally had to cede that it wasn't working.  Thank you all again and apologize for the delayed response.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been sent a PowerPoint presentation file and wondered why it filled your mailbox? Or have you ever sent a PowerPoint presentation by email and received complaints about the size? Or have you ever created a PowerPoint presentation and t…
Setting the Scene PowerPoint is a creative tool in the right hands but it also includes a much underutilised programming dimension. In this beginner level article, we're going to show you some of some key elements of programming PowerPoint using th…
This video teaches viewers how to fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.
The viewer will learn how to edit the master slide. They will also learn how to combine multiple themes into one master slide to use them in their presentation.

734 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