LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Check for named shape in chart

On Sun, 11 Feb 2007 22:13:27 -0500, "Jon Peltier"
wrote:


"Fredrik E. Nilsen" wrote in message
.. .
Hi,

If I have understood it correctly, there is no way to control the
placement of the Axis title object in a chart or control the text line
breaks in it through VB.


You can easily get or set the position of an axis title:

Sub AxisTitlePlacement()
If ActiveChart.HasAxis(xlValue, xlPrimary) Then
If ActiveChart.Axes(xlValue, xlPrimary).HasTitle Then
With ActiveChart.Axes(xlValue, xlPrimary).AxisTitle
' get axis title position
MsgBox "Axis Position Left: " & .Left & ", Top: " & .Top
' set axis title position
.Left = 0
.Top = ActiveChart.PlotArea.Height / 2 +
ActiveChart.PlotArea.InsideTop - 12
End With
End If
End If
End Sub


Ah, thank you. I was mislead by a couple of blogs, and I couldn't find
any documentation about it in the help-file.

Line breaks are not as straightforward. You cannot make the line any longer
than Excel decides (other than by shrinking the text or stretching the
chart), but you could insert hard breaks. You would have to write code smart
enough to read the text

MyText = ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text

and decide where a break should be.

Text boxes are in fact the way to get around the limitation you have in
resizing the title box.


The problem is that they don't want a line break for the axis-title at
all so I guess text boxes is the only way to go.

This procedure looks for a textbox with a particular name. If it finds it,
it updates the text. If it doesn't find it, it adds a new one, names it, and
adds text.

Sub UpdateOrAddTextBox()
Dim shp As Shape
Dim bTitleFound As Boolean
If ActiveChart.Shapes.Count 0 Then
For Each shp In ActiveChart.Shapes
If shp.Name = "textbox_YAxisTitle" Then
' we found it
bTitleFound = True
' adjust text and position of textbox
shp.TextFrame.Characters.Text = "New Y Axis Title"
End If
Next
End If
If Not bTitleFound Then
' didn't find it, so add it
Set shp = ActiveChart.Shapes.AddTextbox(msoTextOrientationUp ward, 0, _
ActiveChart.PlotArea.Height / 2 + ActiveChart.PlotArea.InsideTop -
12, 20, 100)
With shp
.Name = "textbox_YAxisTitle"
.TextFrame.Characters.Text = "Y Axis Title"
.TextFrame.AutoSize = True
End With
End If
End Sub


Fantastic, I will try this in the morning! Now it's 5 am local time, I
can barely read what you have written...:)

Thanks again!

--
Fredrik E. Nilsen
 
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
chart over a shape Laoballer Charts and Charting in Excel 1 January 30th 09 09:26 AM
Excel 2003: How to nudge a chart element or shape on a chart? Ted M H Charts and Charting in Excel 5 June 30th 08 07:08 PM
check whether shape is a group Claude Excel Programming 12 August 31st 06 01:03 PM
Shape ControlFormat.LinkedCell returns wrong Address for named range - BUG [email protected] Excel Programming 10 July 14th 06 03:05 PM
Chart in a Shape QPapillon Excel Discussion (Misc queries) 1 June 26th 06 04:17 PM


All times are GMT +1. The time now is 10:45 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"