Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-20-2012, 04:10 AM
cole10 cole10 is offline VBA Picture Positioning Windows 7 64bit VBA Picture Positioning Office 2010 64bit
Novice
VBA Picture Positioning
 
Join Date: Sep 2012
Posts: 3
cole10 is on a distinguished road
Question VBA Picture Positioning

I have a powerpoint slide that has 5 images on it. I have written a code that crops all images, resizes them and then aligns them centrally, but i want each image to be in the vertical position 100 points below the one above. Currently my code looks like this:

Sub CropResize()
Dim sldTemp As Slide
Dim lngTemp As Long
Dim lngCount As Long
For Each sldTemp In ActivePresentation.Slides
For lngCount = sldTemp.Shapes.Count To 1 Step -1
With sldTemp.Shapes(lngCount)
.PictureFormat.CropLeft = 100
.PictureFormat.CropTop = 55
.PictureFormat.CropRight = 70
.PictureFormat.CropBottom = 100
.LockAspectRatio = msoTrue
.Height = 100
.IncrementLeft 275


.IncrementTop 100

End With
Next
Next
Set screens = ActivePresentation.Slides(1)
screens.Shapes.Range.Align msoAlignCenters, msoTrue
End Sub


Which positions the top image perfectly, but i then want the one below to be at vertical position 100 + 100 and the third image to be 100 + 200 (ie 100 + image# x 100). I thought about using a 'for' function so for image 1 to 5 position is 100+image*100 type function but can't get it to work, it always comes up as an error. all help welcome please! (Sorry if i havent been clear!)
Reply With Quote
  #2  
Old 09-20-2012, 04:58 AM
JohnWilson JohnWilson is offline VBA Picture Positioning Windows 7 64bit VBA Picture Positioning Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,822
JohnWilson will become famous soon enoughJohnWilson will become famous soon enough
Default

Does this do it?

Sub CropResize()
Dim osld As Slide
Dim oshp As Shape
Dim x As Integer
On Error Resume Next
For Each osld In ActivePresentation.Slides
If osld.SlideIndex > 1 Then Exit Sub
For Each oshp In osld.Shapes
If CheckIsPic(oshp) = True Then
With oshp
.PictureFormat.CropLeft = 100
.PictureFormat.CropTop = 55
.PictureFormat.CropRight = 70
.PictureFormat.CropBottom = 100
.LockAspectRatio = msoTrue
.Height = 100
.Top = x * 100
End With
x = x + 1
End If
Next oshp
osld.Shapes.Range.Align msoAlignCenters, msoTrue
Next osld
End Sub

Function CheckIsPic(oshp As Shape) As Boolean
If oshp.Type = msoPicture Then CheckIsPic = True
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Then CheckIsPic = True
End If
End Function
__________________
Microsoft PowerPoint MVP
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #3  
Old 09-20-2012, 05:47 AM
cole10 cole10 is offline VBA Picture Positioning Windows 7 64bit VBA Picture Positioning Office 2010 64bit
Novice
VBA Picture Positioning
 
Join Date: Sep 2012
Posts: 3
cole10 is on a distinguished road
Default

Thanks John that is exactly what I was after, its fantastic! Wasn't aware of the .Top function to position, but its ideal. Is there anyway I can position them (aligned) off centre? i.e have them all in a neat column but to the left of the slide? Thank you again!
Reply With Quote
  #4  
Old 09-20-2012, 06:46 AM
JohnWilson JohnWilson is offline VBA Picture Positioning Windows 7 64bit VBA Picture Positioning Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,822
JohnWilson will become famous soon enoughJohnWilson will become famous soon enough
Default

Try this

Sub CropResize()
Dim osld As Slide
Dim oshp As Shape
Dim x As Integer

For Each osld In ActivePresentation.Slides
If osld.SlideIndex > 1 Then Exit Sub
For Each oshp In osld.Shapes
If CheckIsPic(oshp) = True Then
With oshp
.PictureFormat.CropLeft = 100
.PictureFormat.CropTop = 55
.PictureFormat.CropRight = 70
.PictureFormat.CropBottom = 100
.LockAspectRatio = msoTrue
.Height = 100
.Top = x * 100
.Select Replace:=False 'Select picture but keep any others selected
End With
x = x + 1
End If
Next oshp
'this is a better method as it will exclude any non pictures
With ActiveWindow.Selection.ShapeRange
.Align (msoAlignCenters), msoTrue
.Left = 10
End With
Next osld
End Sub

Function CheckIsPic(oshp As Shape) As Boolean
If oshp.Type = msoPicture Then CheckIsPic = True
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Then CheckIsPic = True
End If
End Function
__________________
Microsoft PowerPoint MVP
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #5  
Old 09-20-2012, 06:55 AM
cole10 cole10 is offline VBA Picture Positioning Windows 7 64bit VBA Picture Positioning Office 2010 64bit
Novice
VBA Picture Positioning
 
Join Date: Sep 2012
Posts: 3
cole10 is on a distinguished road
Default

yes thats perfect, huge thank you!
Reply With Quote
Reply

Tags
image display, positioning, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Positioning drawing elements in Powerpoint TdeV PowerPoint 2 09-20-2014 06:56 AM
Move Picture by picture name, rename picture by picture name CatMan PowerPoint 2 04-18-2012 12:21 PM
Powerpoint automatically changing picture size when adding a picture (2010) One_Life PowerPoint 7 01-20-2012 06:57 AM
URGENT!!! Powerpoint Image Formatting and Positioning Macro mertulufi PowerPoint 5 12-20-2011 10:14 AM
VBA Picture Positioning Positioning Slide Titles genericusername PowerPoint 3 03-17-2011 05:43 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 01:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft