Reputation: 2776
I want to remove the line break that I have in a certain text. I check in this forum how to do it and there were several answers but no one works for me at least in powerpoint.
I saw one example with left method:
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 If
text = Left (text, number)
gives me Type mismatch error
text = Left$ (text, number)
gives me compile error: Type-declaration character does not match declared data type.
I also try to replace the line break with "" but it just did nothing. It didn't gave me an error but the line break was still there.
The line break that I am using is vbCrLf
Upvotes: 0
Views: 2659
Reputation: 46365
For the object in which you want to remove the vbCrLf
, try using
myObj.TextFrame.TextRange.Replace vbCrLf, ""
If you want to do this to a string (not an object) you can try something like this:
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
As you will see, this removes the line breaks. Adapt for your purpose...
edit As Steve Rindsberg pointed out, it may be that your version of Powerpoint is using something other than vbCrLf
as the paragraph delimiting character. Here is some code to help you figure this out - for each shape with text in it, it will extract the text, showing all "control characters" (ASCII value < 32) as \xnn
where nn
is the value of the control character (so that vbCR
will display as \x13
for example):
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
A simple test showed that in PowerPoint 2010 you do have just \x13
at the end of a paragraph...
Upvotes: 0
Reputation: 14809
Your problem is likely that versions of PPT since 2007 don't use VBCrLf as a paragraph-ending character. This explains which versions use what characters for line or paragraph ends:
Paragraph endings and line breaks http://www.pptfaq.com/FAQ00992_Paragraph_endings_and_line_breaks.htm
It's from the PPT FAQ site that I maintain.
Upvotes: 1