VBA vbNewLine 但没有额外空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37273817/
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
VBA vbNewLine but with no extra space
提问by Mauro Augusto
I'm adding a Title to a chart but I keep getting an extra space (white space) between the two strings when I use vbNewLine.
我正在向图表添加一个标题,但是当我使用 vbNewLine 时,我在两个字符串之间不断得到一个额外的空格(空白)。
myChart.ChartTitle.Text = "Distance to Default for" & vbNewLine & compName
note compNameis another string I previously define.
notecompName是我之前定义的另一个字符串。
回答by Mauro Augusto
Most probably it's a text format issue. Try: vbCrLf, vbCr, vbLfor (digged up the doc) Environment.NewLine. One of the four should be OK.
"Cr" is "carriage return" while "Lf" is "Line Feed" (these terms come from old typewriter times). Some OS/text format/system/whatever uses both "driver characters", some use just one of these - the white space you saw was an unnecessary "cr" or "lf" if that makes sense
很可能是文本格式问题。尝试:vbCrLf, vbCr, vbLfor (digged up the doc) Environment.NewLine。四个之一应该没问题。
“Cr”是“回车”,而“Lf”是“换行”(这些术语来自旧打字机时代)。一些操作系统/文本格式/系统/任何使用“驱动程序字符”的东西,有些只使用其中一个 - 如果有意义的话,您看到的空白是不必要的“cr”或“lf”
回答by smozgur
Try vbCrLf:
试试 vbCrLf:
myChart.ChartTitle.Text = "Distance to Default for" & vbCrLf & compName
EDIT: Try vbCrsince vbCrLflooks to be identical to vbNewline
编辑:尝试vbCr因为vbCrLf看起来与vbNewline
myChart.ChartTitle.Text = "Distance to Default for" & vbCr & compName
回答by Sorcefyre
I don't understand what end result you're aiming for, but using vbNewLine will insert a carriage return.
我不明白你的目标是什么最终结果,但使用 vbNewLine 会插入一个回车。
If you're just trying to insert a space between the text and the value then one of the following would work:
如果您只是想在文本和值之间插入一个空格,则可以使用以下方法之一:
myChart.ChartTitle.Text = "Distance to Default for " & compNamemyChart.ChartTitle.Text = "Distance to Default for " & compNamemyChart.ChartTitle.Text = "Distance to Default for" & Chr(32) & compNamemyChart.ChartTitle.Text = "Distance to Default for" & Chr(32) & compName回答by Expenzor
So here's my solution. Use chr(10)instead of vbNewLineand then do this:
所以这是我的解决方案。使用chr(10)代替vbNewLine然后执行以下操作:
compName = Replace(compName, vbCrLf, Chr(10))
compName = Replace(compName, vbCrLf, Chr(10))
It worked for me. Don't know if it'll work for everyone. Cheers.
它对我有用。不知道对大家有没有用。干杯。

