vba 防止图表数据标签换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19301606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Keep Chart Data Label from Wraping
提问by user2808271
I have a project where I have to put user generated data labels in a chart. These need to be on a series line as such:
我有一个项目,我必须将用户生成的数据标签放在图表中。这些需要在一个系列的线上:
![What I want format][1]
![我想要的格式][1]
However in some instances the text wraps. How do I keep the text from wrapping in excel 10? see below
但是,在某些情况下,文本会换行。如何防止文本在 excel 10 中换行?见下文
![enter image description here][2]
![在此处输入图像描述][2]
'-------- FORMAT DATA LABELS -------------------------------------
'-------- 格式化数据标签 -------------------------------------
ActiveSheet.ChartObjects("OperBal2Takt").Activate
h = 0
For h = 2 To 7
With ActiveChart.SeriesCollection(h).Points(1)
.HasDataLabel = True
.DataLabel.Text = Cells(2018 + h, 8).Value
'.DataLabel.Width = msofit
End With
Next h
回答by Jon Peltier
In Excel 2013, the size of your data label can be changed. In previous versions, the label cannot be resized.
在 Excel 2013 中,可以更改数据标签的大小。在以前的版本中,无法调整标签大小。
In earlier Excel versions, sometimes I've stretched the chart to make it wider, but shrunk the plot area of the chart down to the original size, so the white space is wider on both sides of the chart. This works because the maximum size of a label is proportional to the chart width.
在早期的 Excel 版本中,有时我会拉伸图表以使其更宽,但将图表的绘图区域缩小到原始大小,因此图表两侧的空白区域更宽。这是有效的,因为标签的最大尺寸与图表宽度成正比。
Other times I've replaced the data label with a text box, which can be flexibly resized.
其他时候我用一个文本框替换了数据标签,它可以灵活地调整大小。
回答by Patrick Lepelletier
use this code:
使用此代码:
ChartObj.chart.seriescollection(1).datalabels.Format.TextFrame2.WordWrap = msoFalse
and also, but less usefull:
而且,但不太有用:
ChartObj.chart.seriescollection(1).datalabels.Format.TextFrame2.AutoSize = msoAutoSizeNone