这个奇怪的角色是什么,我怎么能摆脱它呢?

时间:2010-11-03 20:24:15

标签: .net string vba powerpoint powerpoint-vba

这在.NET和VBA中均有显示。男性标志:

mo fo

你会注意到第4,5,6,8,10和12行,那里有一个额外的角色。这是一个段落标记。第3行是制表符,但只显示为空格。

当我尝试在PowerPoint中抓取.TextRange.Text的文本时会发生这种情况。上面是VBE中的立即窗口,但是当我尝试将文本放在控件中时,它也会显示.NET控件,例如ListView。

可以通过打开一个新的PowerPoint演示文稿然后在VBE中运行来复制它:

Sub Replicate()
    Dim ap As Presentation: Set ap = ActivePresentation
    Dim sl As Slide: Set sl = ap.Slides(1)
    sl.Shapes.Title.TextFrame.TextRange.Text = "One bad" & vbCrLf & "MOFO"
    Debug.Print s.Shapes.Title.TextFrame.TextRange.Text
End Sub

如何摆脱这种情况(即只显示男性标志)?这是我的控件的某种Unicode设置还是字符串上的RegEx或......?

3 个答案:

答案 0 :(得分:0)

听起来像Powerpoint没有使用VB正在使用的相同的回车换行约定。您可能必须使用不同的换行约定替换vbCrLf(使您自己的字节数组对要插入)。

答案 1 :(得分:0)

而非vbCrLf使用此vbLf & vbCr

Sub Replicate()
    Dim ap As Presentation: Set ap = ActivePresentation
    Dim sl As Slide: Set sl = ap.Slides(1)
    sl.Shapes.Title.TextFrame.TextRange.Text = "One bad" & vbLf & vbCr & "Line Feed above me"
End Sub

alt text

答案 2 :(得分:0)

本文将帮助Exploring the PowerPoint TextRange Object,但请注意,当它来自标题占位符时,它是Chr(11)而不是Chr(13)。您可以使用TextRange.Replace(ChrW(11), " ")对其进行清理。