对于要删除的对象,请vbCrLf
尝试使用
myObj.TextFrame.TextRange.Replace vbCrLf, ""
如果您想对字符串(而不是对象)执行此操作,可以尝试以下操作:
Sub stripStrings()
Dim longString As String
Dim stringCopy As String
longString = "first paragraph" & vbCrLf & "second paragraph" & vbCrLf & "third paragraph" & vbCrLf
stringCopy = Replace(longString, vbCrLf, "")
MsgBox "longstring is now:" & vbCrLf & longString
MsgBox "stringcopy is:" & vbCrLf & stringCopy
End Sub
正如您将看到的,这将删除换行符。适应你的目的...
编辑正如 Steve Rindsberg 指出的那样,可能是您的 Powerpoint 版本使用的不是vbCrLf
段落分隔符。这里有一些代码可以帮助您解决这个问题 - 对于其中包含文本的每个形状,它将提取文本,显示所有“控制字符”(ASCII 值 < 32)作为控制字符\xnn
的nn
值(这样vbCR
将显示\x13
例如):
Sub displayControlCharacters()
Dim sh As Shape
Dim t As String
For Each sh In ActivePresentation.Slides(1).Shapes
If sh.TextFrame.HasText Then
sh.Select
t = sh.TextFrame.TextRange.Text
MsgBox "The shape contains: " & vbCrLf & escapeString(t)
End If
Next sh
End Sub
Function escapeString(t As String)
Dim ii As Integer
Dim r As String
For ii = 1 To Len(t)
If Asc(Mid(t, ii, 1)) > 31 Then
r = r + Mid(t, ii, 1)
Else
r = r + "\x" + Format(Asc(Mid(t, ii, 1)), "0")
End If
Next
escapeString = r
End Function
一个简单的测试表明,在 PowerPoint 2010 中,您确实\x13
在段落末尾...