View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Determining whether a named textbox on a chart exists

My only comment would be that you error handling jumps out if there is an
error in processing an existing textbox. while I can't imagine what would
cause an error, nonetheless, jumping out on the first textbox would abandon
the remaining. I think I would just On Error resume Next that whole section
of code. If you do have problems, you will want to comment these lines out
for trouble shooting, but since you know the code is working under normal
circumstances, I don't see it as an issue for production.

Sub ResetTextBoxes()
Dim tbTitles As Variant
Dim tbTop As Variant
Dim tbLeft As Variant
Dim tb As Shape
Dim Counttb As Integer

tbTitles = Array("footer", "Chart Title", "Subtitle") ', "Axis Label")
tbTop = Array(280, 2, 34)
tbLeft = Array(5, 50, 50)

myChart.Chart.PlotArea.Top = 40

On Error Resume Next
For Counttb = LBound(tbTitles) To UBound(tbTitles)
Set tb = myChart.Chart.Shapes(tbTitles(Counttb))
If Not tb Is Nothing Then 'now position tb
tb.Top = tbTop(Counttb)
tb.Left = tbLeft(Counttb) '5
End If
Set tb = Nothing
Next
On Error goto 0
End Sub

--
Regards,
Tom Ogilvy


"preetidb" wrote in message
ups.com...
Hi

I've developed the above code into this:

Sub ResetTextBoxes()
Dim tbTitles As Variant
Dim tbTop As Variant
Dim tbLeft As Variant
Dim tb As Shape
Dim Counttb As Integer

tbTitles = Array("footer", "Chart Title", "Subtitle") ', "Axis Label")
tbTop = Array(280, 2, 34)
tbLeft = Array(5, 50, 50)

myChart.Chart.PlotArea.Top = 40

For Counttb = LBound(tbTitles) To UBound(tbTitles)
On Error Resume Next
Set tb = myChart.Chart.Shapes(tbTitles(Counttb))
On Error GoTo ErrorLine
If Not tb Is Nothing Then 'now position tb
tb.Top = tbTop(Counttb)
tb.Left = tbLeft(Counttb) '5
End If
Set tb = Nothing
Next

ErrorLine:
Set tb = Nothing

End Sub

Any comments/advise would be appreciated. Is this the best approach?

Many thanks
Preeti