Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Chart - Title Widths

Chart - Title Widths

Does anyone know how to find the width of a title/axis title?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Chart - Title Widths

Hi,

The charttitle, along with the other labelling items in a chart, do not
expose the Width or Height properties.

Try this workaround. (Beware of word wrapping).

'------------------
Sub X
MsgBox GetChartTitleWidth(ActiveChart)
End Sub

Function GetChartTitleWidth(MyChart As Chart) As Single
Dim sngOrigLeft As Single
If MyChart.HasTitle Then
sngOrigLeft = MyChart.ChartTitle.Left
MyChart.ChartTitle.Left = MyChart.ChartArea.Left +
MyChart.ChartArea.Width
GetChartTitleWidth = (MyChart.ChartArea.Width -
MyChart.ChartArea.Left) - MyChart.ChartTitle.Left
MyChart.ChartTitle.Left = sngOrigLeft
End If
End Function
'------------------

It uses the fact that the chart title can not be more beyond the area of
the chart. The routine tries and then uses the gap between the edge and
the new Left position to determine the width. Should be close enough.

Obvioulsy the same technique can be applied to get the height


wrote:

Chart - Title Widths

Does anyone know how to find the width of a title/axis title?



--

Cheers
Andy

http://www.andypope.info

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Chart - Title Widths

You have to do this indirectly, since as you've learned, the charttitle
object exposes no width (or height) property to VBA. But if you move it
as far to the right as possible, then the width of the chart minus the
left position of the charttitle is equal to the charttitle width.

activechart.ChartTitle.left = activechart.ChartArea.width

ChartAreaWidth = activechart.ChartArea.width - _
activechart.ChartTitle.left

Some simple experiments with the legend, which does expose its width,
indicates that the width calculated above is about 3 points too large.

To center the chart title, use this:

activechart.ChartTitle.left = activechart.ChartArea.width
activechart.ChartTitle.left = activechart.ChartTitle.left/2

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
http://PeltierTech.com/Excel/Charts/
_______

wrote:

Chart - Title Widths

Does anyone know how to find the width of a title/axis title?



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
How to hide a chart title, but keep the title in the chart KBratt Charts and Charting in Excel 1 July 16th 09 12:13 AM
Possible to change chart title and label box widths? [email protected] Charts and Charting in Excel 6 December 18th 06 09:44 PM
Excel chart - how to assign the file name in the chart title? TGreen Charts and Charting in Excel 1 August 16th 05 10:35 AM
Pasting Objects into Chart title and Axis title Sam Charts and Charting in Excel 1 June 6th 05 08:50 PM
Bar Chart Bar Widths Jon Charts and Charting in Excel 4 May 27th 05 03:41 AM


All times are GMT +1. The time now is 06:14 AM.

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"