Solved

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

Posted on 2015-01-18
7
398 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
7 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 40556959
0
 
LVL 50

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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 11

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 11

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy a row 12 64
Powerpoint 2013 - Footers with dates/times are NOT appearing in the footers 3 63
How to make an ADE file by code? 11 94
PowerPoint 2013 Issues 9 56
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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.

828 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