Ashkan Lotfipour
asked on
Distributing two picture in each slide of a powerpoint
Hi there
I have 5 presentations with a large number of slides which each of slides has to pictures in them (before and after). I want a VBA code to distribute these pictures horizontally. I've found a code for one picture, so it won't work on my presentations.
Sub DHori()
Dim osld As Slide
For Each osld In ActivePresentation.Slides
With osld.Shapes.Range
.Distribute msoDistributeHorrizontally , msoTrue
End With
Next osld
End Sub
I also have another question, all of these pictures are linked in presentation, so each week when opening my presentation they update automatically. is there a code for breaking these links, so I wouldn't have to do this manually?
I have 5 presentations with a large number of slides which each of slides has to pictures in them (before and after). I want a VBA code to distribute these pictures horizontally. I've found a code for one picture, so it won't work on my presentations.
Sub DHori()
Dim osld As Slide
For Each osld In ActivePresentation.Slides
With osld.Shapes.Range
.Distribute msoDistributeHorrizontally
End With
Next osld
End Sub
I also have another question, all of these pictures are linked in presentation, so each week when opening my presentation they update automatically. is there a code for breaking these links, so I wouldn't have to do this manually?
Try this:
Sub DHori()
Dim osld As Slide
Dim oshp As Shape
Dim oshpR As ShapeRange
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If isPic(oshp) Then
oshp.Select False
End If
Next
Set oshpR = ActiveWindow.Selection.ShapeRange
oshpR.Distribute msoDistributeHorizontally, msoTrue
oshpR.Align msoAlignMiddles, True
Next osld
End Sub
Function isPic(oshp As Shape) As Boolean
If oshp.Type = msoPicture Or oshp.Type = msoLinkedPicture Then isPic = True
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Or _
oshp.PlaceholderFormat.ContainedType = msoLinkedPicture Then isPic = True
End If
End Function
ASKER
Thank you very much for your helpful responses.
Rgonzo code is great for breaking links, but it has a compile error (subscript out of range) in this line:
strShapes(idx) = shp.Name
as for Mr. Wilson's, it has a different error. (Invalid request. to select a shape, its view must be active.) on this line:
oshp.Select False
My office version is 2016 and my pictures have a unique id, Don't know if it matters.
Rgonzo code is great for breaking links, but it has a compile error (subscript out of range) in this line:
strShapes(idx) = shp.Name
as for Mr. Wilson's, it has a different error. (Invalid request. to select a shape, its view must be active.) on this line:
oshp.Select False
My office version is 2016 and my pictures have a unique id, Don't know if it matters.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works like a charm.
Thank you very much for your code. and also Rgonzo1971, for his breaking link code.
Thank you very much for your code. and also Rgonzo1971, for his breaking link code.
pls try
Open in new window
Regards