I have some VBA code in Excel that creates shapes with text inside.
This works fine for me. But here is the twist .......
Would it be possible to check if an exact same shape (and text) already exists in the same location and prevent another creation of the same object. In other words prevent duplication.
I thought about running a FOR-LOOP around all the shapes on the sheet and check individually for an exact match and then prevent the code above running again. The problem I have with this is that I may end up with multiple shapes on one sheet and it would get slower and slower in checking all available shapes.
Any ideas or clues ?
Thanks.
Code:
Sub draw_text(x As Integer, y As Integer, text_string As String)
Dim sht1 as Object
Set sht1 = Sheets(1)
With sht1.Shapes.AddShape(msoShapeRoundedRectangle, x, y, 60, 15)
.TextFrame.Characters.Text = text_string
End With
End Sub
This works fine for me. But here is the twist .......
Would it be possible to check if an exact same shape (and text) already exists in the same location and prevent another creation of the same object. In other words prevent duplication.
I thought about running a FOR-LOOP around all the shapes on the sheet and check individually for an exact match and then prevent the code above running again. The problem I have with this is that I may end up with multiple shapes on one sheet and it would get slower and slower in checking all available shapes.
Any ideas or clues ?
Thanks.