我想删除某个文本中的换行符。我在这个论坛上查看了如何做到这一点,有几个答案,但没有人为我工作,至少在powerpoint。
我看到了一个使用left方法的示例:
If Len(myString) <> 0 Then
If Right$(myString, 2) = vbCrLf Or Right$(myString, 2) = vbNewLine Then
myString = Left$(myString, Len(myString) - 2)
End If
End Iftext = Left (text, number)显示类型不匹配错误
text = Left$ (text, number)给了我compile error: Type-declaration character does not match declared data type.
我也尝试将换行符替换为"“,但它什么也没做。它没有给我一个错误,但换行符仍然在那里。
我使用的换行符是vbCrLf
发布于 2013-07-01 22:43:16
您的问题可能是2007年以后的PPT版本不使用VBCrLf作为段落结束字符。这说明了哪些版本的行尾或段落末尾使用什么字符:
段落结束和换行符http://www.pptfaq.com/FAQ00992_Paragraph_endings_and_line_breaks.htm
它来自我维护的PPT常见问题网站。
发布于 2013-07-01 20:15:02
对于要删除其中的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……
https://stackoverflow.com/questions/17404167
复制相似问题