Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2015-01-18
7
Medium Priority
?
447 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 46

Expert Comment

by:aikimark
ID: 40556959
0
 
LVL 52

Assisted Solution

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

pls try

oshp.ScaleWidth dblscaleamount, msoFalse, msoScaleFromMiddle

Regards
0
 
LVL 23

Assisted Solution

by:JSRWilson
JSRWilson earned 668 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Accepted Solution

by:
Jamie Garroch earned 664 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
A lot of things can happen during a presentation, worst of which is “death by PowerPoint.” Here are a few mistakes to avoid to make your slides clean.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
The viewer will learn how to edit animations within the presentation, incorporate sound, and set everything up with timing.

688 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