dreid1011
Well-known Member
- Joined
- Jun 4, 2015
- Messages
- 3,613
- Office Version
- 365
- Platform
- Windows
Good afternoon,
In an attempt to solve another's problem, I am playing with shapes. I am trying to detect overlapping shapes created through vba on demand. I have a list of x and y coordinates and convert those to a position on a chart.
The problem I am running into at the moment, is that two shapes with the same (x, y) values do not have identical .Left values and it's boggling my mind.
The code is placing them at exactly the same place, but when I Debug.Print the values for .Left of each one, they show completely different numbers. This of course, is throwing off any attempt to detect if the shapes are overlapping.
The highlighted portion is where I am attempting to adjust for overlaps.. Of course, it's not complete at the moment as I was just trying to identify why it wasn't working. (I've changed/deleted some code lines..)
Anyway, when i = 29, tB1 is the last shape created and should have identical .left and .top values to the previous shape as both their (x, y) values are (3, 3) and thus placed at the same point. tB1 and ws.Shapes(24) and ws.Shapes(25) should have the same values.
But this is what I see from debug.print:
tB1.Left = 842.25
ws.Shapes(24).Left = 1640.25 24
ws.Shapes(25).Left = 962.25 25
I'm very confused.
In an attempt to solve another's problem, I am playing with shapes. I am trying to detect overlapping shapes created through vba on demand. I have a list of x and y coordinates and convert those to a position on a chart.
The problem I am running into at the moment, is that two shapes with the same (x, y) values do not have identical .Left values and it's boggling my mind.
The code is placing them at exactly the same place, but when I Debug.Print the values for .Left of each one, they show completely different numbers. This of course, is throwing off any attempt to detect if the shapes are overlapping.
Rich (BB code):
Private Sub InsertTextBoxes()
Dim tB1 As Shape, tB2 As Shape
Dim ws As Worksheet
Dim i As Long, j As Long, k As Long
Dim xVal As Variant, yVal As Variant
Set ws = Worksheets("Sheet1")
j = ws.Range("C" & Rows.Count).End(xlUp).Row
xVal = Split("0,40,32,24,16,8", ",")
yVal = Split("0,L,P,T,X,AB", ",")
For i = 5 To j
Set tB1 = ws.Shapes.AddTextbox(msoTextOrientationHorizontal, Range(yVal(Range("D" & i).Value) & xVal(Range("C" & i).Value)).Left + 15, Range(yVal(Range("D" & i).Value) & xVal(Range("C" & i).Value)).Top + 7, 30, 15)
tB1.TextFrame.Characters.Text = ws.Range("B" & i).Address(0, 0)
tB1.TextFrame.HorizontalAlignment = xlHAlignCenter
tB1.TextFrame.VerticalAlignment = xlVAlignCenter
tB1.TextFrame.Characters.Font.Size = 8
If i = 29 Then
Debug.Print "X"
Debug.Print tB1.Left
Debug.Print ws.Shapes(24).Left & " 24"
Debug.Print ws.Shapes(25).Left & " 25"
If tB1.Left = ws.Shapes(i - 5).Left Then
Debug.Print "Y"
' tB1.IncrementLeft -31
' tB1.IncrementTop -16
End If
End If
Next i
End Sub
The highlighted portion is where I am attempting to adjust for overlaps.. Of course, it's not complete at the moment as I was just trying to identify why it wasn't working. (I've changed/deleted some code lines..)
Anyway, when i = 29, tB1 is the last shape created and should have identical .left and .top values to the previous shape as both their (x, y) values are (3, 3) and thus placed at the same point. tB1 and ws.Shapes(24) and ws.Shapes(25) should have the same values.
But this is what I see from debug.print:
tB1.Left = 842.25
ws.Shapes(24).Left = 1640.25 24
ws.Shapes(25).Left = 962.25 25
I'm very confused.