Sorry, here is the same code with clearer layout:

For Each Shp In Application.ActiveDocument.Shapes
If Shp.TextFrame.HasText Then
'Doing some actions
'This part is working well
Else 'Check if the shape contains one or more textboxes
On Error GoTo ShapeErrorHandler
If Shp.GroupItems.Count > 0 Then
Shp.Ungroup
End If
For i = 1 To Shp.CanvasItems.Count
ShapeErrorHandler:
Err.Clear
Exit For
Next i
End If
Next