PDA

View Full Version : Comparing Shape Properties in a Group



unclebiff
08-06-2016, 11:59 AM
Hey everyone. I am trying to write a program that allows the user to define the space between two shapes. When I try to run the program I get an error that says "Method or Data Member Not Found" when I use .Group. I am relatively new to VBA but have experience working in the C++ environment. The code:


Sub Spacer()


Dim sel As GroupShapes
Dim TopShape As Shape
Dim BottomShape As Shape
Dim Space As Single
Dim x As Single


sel = ActiveWindow.Selection.ShapeRange(1).Group
If sel.Item(1) > sel.Item(2) Then
TopShape = sel.Item(1)
BottomShape = sel.Item(2)
Else
TopShape = sel.Item(2)
BottomShape = sel.Item(1)
End If


Space = TopShape.Height - BottomShape.Height
x = InputBox("Bottom Space:")
For i = Space To x
BottomShape.IncrementTop 1
i = TopShape.Height - BottomShape.Height
Next i


End Sub

Anyone have any ideas why the Group does not work? Also, if you have any other pointers or ideas, let me know!

SamT
08-07-2016, 12:25 AM
I'm not sure, but looking at this line, makes me wonder which Group.Item Property is being compared. It may not be numerical.

If sel.Item(1) > sel.Item(2) Then
I kinda suspect that if you specified which Property you were comparing, it might work. ie:

If sel.Item(1).Width > sel.Item(2).Width Then



In any case, this will bump your thread back to the top. I also re titled this thread to, IMO, better intice somebody who does know PowerPoint.

John Wilson
08-07-2016, 01:05 AM
Sub Spacer()

Dim sel As GroupShapes
Dim TopShape As Shape
Dim BottomShape As Shape
Dim Space As Single
Dim x As Single
On Error Resume Next
If ActiveWindow.Selection.ShapeRange(1).Type <> msoGroup Then Exit Sub
Set sel = ActiveWindow.Selection.ShapeRange(1).GroupItems
If sel.Item(1).Top > sel.Item(2).Top Then
Set TopShape = sel.Item(2)
Set BottomShape = sel.Item(1)
Else
Set TopShape = sel.Item(1)
Set BottomShape = sel.Item(2)
End If
x = InputBox("Bottom Space:")
Space = (TopShape.Top + TopShape.Height) - (BottomShape.Top)
BottomShape.Top = TopShape.Top + TopShape.Height + x
End Sub