juanbolas
02-04-2022, 07:55 PM
Hello everyone,
I've been trying to work this out but am stuck.
My main problem is that I can't select a shape after ungrouping - referencing the 2 o 3 ungrouped items.
I have a series of flow chart shapes that have a reference number on the top left of the main. shape. They number in the hundreds now. Because I was lazy, some of the shapes have the reference number and the main shape grouped together, others don't, Additionally some shapes have an additional grouping with a text shape to increase text area (the decision shape for example). The main shape and textbox are (or should be the same size).
Due to the holes I have in the code, I haven't been able to test what I've written so far.
Thanks in advance for your help!
Sub FormatFlowChartShape()
Dim oSlide As slide
Dim oShape As Shape
Dim oNewShape As Shape
Dim AreaTolerance As Integer
Dim ShapeNumberHeight As Integer
Dim ShapeNumberWidth As Integer
''AreaTolerance = 0.2 '' shape may be +/-20%
ShapeNumberHeight = 19.85
ShapeNumberWidth = 19.85
ShapeMainHeight = 48.76
ShapeMain Width = 119.65
Set oSlide = Application.ActiveWindow.View.slide
Set oShape = ActiveWindow.Selection.ShapeRange(1)
' store shape position of posibly grouped shape
With oShape
ShapeLeft = .Left
ShapeTop = .Top
ShapeWidth = .Width
ShapeHeight = .Height
End With
' ungroup shapes if necessary
If oShape.GroupItems.Count > 0 Then
If oShape.Type = msoGroup Then
oShape.Ungroup
' in some cases there are two grouping levels
' because a textbox is used for more text space
oShape.Ungroup
Debug.Print "Ungrouped"
End If
' select first shape
'which is the shapes step number in the flowchart
' it is usually located slightly offset to the
' left and top of the main flowchart shape
' having trouble selecting shape that was in a group
' i was thinking of find shape within the area of the ungrouped shape
' and selecting it. Does this make sense?
' select it -- HELP!!!
' if it doesn't exist, create a new shape
If Not ShapeExists Then
Set oNewShape = oSlide.Shapes.AddShape( _
Type:=msoRoundedRectangle, _
Left:=24, _
Top:=NewSlideTop, _
Width:=ShapeNumberWidth, _
Height:=ShapeNumberHeight)
End If
' format shape stuff goes here
' format
'Now main second shape
' select it -- HELP!!!
'reposition number Shape to main shape
oShape.Left = .Left - ShapeNumberLeft / 2
oShape.Top = .Top - ShapeNumberTop / 2
oShape.Width = ShapeMainWidth
oShape.Height = ShapeMainHeight
End With
' because a textbox is used for more text space
' format shape stuff goes here
' format
' if text box exists process it
' Size
' Format
' Set z-order
' Send geometric shape to back
' if text box Bring text box yo front
' Bring number to front
End Sub
I've been trying to work this out but am stuck.
My main problem is that I can't select a shape after ungrouping - referencing the 2 o 3 ungrouped items.
I have a series of flow chart shapes that have a reference number on the top left of the main. shape. They number in the hundreds now. Because I was lazy, some of the shapes have the reference number and the main shape grouped together, others don't, Additionally some shapes have an additional grouping with a text shape to increase text area (the decision shape for example). The main shape and textbox are (or should be the same size).
Due to the holes I have in the code, I haven't been able to test what I've written so far.
Thanks in advance for your help!
Sub FormatFlowChartShape()
Dim oSlide As slide
Dim oShape As Shape
Dim oNewShape As Shape
Dim AreaTolerance As Integer
Dim ShapeNumberHeight As Integer
Dim ShapeNumberWidth As Integer
''AreaTolerance = 0.2 '' shape may be +/-20%
ShapeNumberHeight = 19.85
ShapeNumberWidth = 19.85
ShapeMainHeight = 48.76
ShapeMain Width = 119.65
Set oSlide = Application.ActiveWindow.View.slide
Set oShape = ActiveWindow.Selection.ShapeRange(1)
' store shape position of posibly grouped shape
With oShape
ShapeLeft = .Left
ShapeTop = .Top
ShapeWidth = .Width
ShapeHeight = .Height
End With
' ungroup shapes if necessary
If oShape.GroupItems.Count > 0 Then
If oShape.Type = msoGroup Then
oShape.Ungroup
' in some cases there are two grouping levels
' because a textbox is used for more text space
oShape.Ungroup
Debug.Print "Ungrouped"
End If
' select first shape
'which is the shapes step number in the flowchart
' it is usually located slightly offset to the
' left and top of the main flowchart shape
' having trouble selecting shape that was in a group
' i was thinking of find shape within the area of the ungrouped shape
' and selecting it. Does this make sense?
' select it -- HELP!!!
' if it doesn't exist, create a new shape
If Not ShapeExists Then
Set oNewShape = oSlide.Shapes.AddShape( _
Type:=msoRoundedRectangle, _
Left:=24, _
Top:=NewSlideTop, _
Width:=ShapeNumberWidth, _
Height:=ShapeNumberHeight)
End If
' format shape stuff goes here
' format
'Now main second shape
' select it -- HELP!!!
'reposition number Shape to main shape
oShape.Left = .Left - ShapeNumberLeft / 2
oShape.Top = .Top - ShapeNumberTop / 2
oShape.Width = ShapeMainWidth
oShape.Height = ShapeMainHeight
End With
' because a textbox is used for more text space
' format shape stuff goes here
' format
' if text box exists process it
' Size
' Format
' Set z-order
' Send geometric shape to back
' if text box Bring text box yo front
' Bring number to front
End Sub