Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Determining whether a named textbox on a chart exists

Hi

I'm using Excel 2003 to generate charts using vba.

On the charts I've created I add a few textboxes that I've named:

myChart.Chart.Shapes.AddTextbox(msoTextOrientation Horizontal, 5, 280, 300,
10).Name = "footer"
myChart.Chart.Shapes.AddTextbox(msoTextOrientation Horizontal, 50, 2, 305,
32).Name = "Chart Title"

What I would like to do is create another macro which users can use to
reformat Charts. This involves checking that the named textbox exists (users
may have deleted it) and if it does position it.

I can not figure out how to do this - can anyone point me in the right
direction?

Many thanks

Preeti


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Determining whether a named textbox on a chart exists

On Error Resume next
set shp = MyChart.Chart.Shapes("footer")
On Error goto 0
if not shp is nothing then
' now position shp
shp.Top = ??
shp.Left = ??
end if

--
Regards,
Tom Ogilvy

"P. Dua-Brown" wrote in message
...
Hi

I'm using Excel 2003 to generate charts using vba.

On the charts I've created I add a few textboxes that I've named:

myChart.Chart.Shapes.AddTextbox(msoTextOrientation Horizontal, 5, 280, 300,
10).Name = "footer"
myChart.Chart.Shapes.AddTextbox(msoTextOrientation Horizontal, 50, 2, 305,
32).Name = "Chart Title"

What I would like to do is create another macro which users can use to
reformat Charts. This involves checking that the named textbox exists

(users
may have deleted it) and if it does position it.

I can not figure out how to do this - can anyone point me in the right
direction?

Many thanks

Preeti




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Determining whether a named textbox on a chart exists

Many thanks Tom

From your code I've managed to create the steps to deal with all three

textboxes:

On Error Resume Next
Set tb = myChart.Chart.Shapes("footer")
On Error GoTo ErrorLine
If Not tb Is Nothing Then
tb.Top = 280
tb.Left = 5
End If
Set tb = Nothing
On Error Resume Next
Set tb = myChart.Chart.Shapes("Chart Title")
On Error GoTo ErrorLine
If Not tb Is Nothing Then
tb.Top = 2
tb.Left = 50
End If
Set tb = Nothing
On Error Resume Next
Set tb = myChart.Chart.Shapes("Subtitle")
On Error GoTo ErrorLine
If Not tb Is Nothing Then
tb.Top = 34
tb.Left = 50
End If

ErrorLine:
Set tb = Nothing
End If

Would I be able to use an array to do this? Any advice would be
appreciated.

Thanks in advance
Preeti



Tom Ogilvy wrote:

On Error Resume next
set shp = MyChart.Chart.Shapes("footer")
On Error goto 0
if not shp is nothing then
' now position shp
shp.Top = ??
shp.Left = ??
end if

--
Regards,
Tom Ogilvy

"P. Dua-Brown" wrote in message
...
Hi

I'm using Excel 2003 to generate charts using vba.

On the charts I've created I add a few textboxes that I've named:

myChart.Chart.Shapes.AddTextbox(msoTextOrientation Horizontal, 5, 280, 300,
10).Name = "footer"
myChart.Chart.Shapes.AddTextbox(msoTextOrientation Horizontal, 50, 2, 305,
32).Name = "Chart Title"

What I would like to do is create another macro which users can use to
reformat Charts. This involves checking that the named textbox exists

(users
may have deleted it) and if it does position it.

I can not figure out how to do this - can anyone point me in the right
direction?

Many thanks

Preeti



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Determining whether a named textbox on a chart exists

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining if a value already exists in column(s) Rookie_User Excel Discussion (Misc queries) 0 October 3rd 06 05:32 PM
how to tell if a named range exists Gixxer_J_97[_2_] Excel Programming 2 June 1st 05 07:38 PM
Determining if a Worksheet Exists Chaplain Doug Excel Programming 3 April 7th 05 10:00 PM
Determining the group a picture or textbox is a member of David Cuthill[_2_] Excel Programming 6 February 12th 04 04:45 PM
Determining if a worksheet exists within a workbook Cory Schneider Excel Programming 1 July 17th 03 12:36 AM


All times are GMT +1. The time now is 11:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"