vbCrLf, what are you???

T

Troot

Hi all,

I have what seems like a simple problem, but can't do it :-(

I am doing up a vba macro for powerpoint, and want to remove the
trailing carriage return from string. Everything I have tried so far
hasn't worked though. Does anybody have a snippet which might be able
to show me how to do this?

Thanks
John
 
S

Steve Rindsberg

Troot said:
Hi all,

I have what seems like a simple problem, but can't do it :-(

I am doing up a vba macro for powerpoint, and want to remove the
trailing carriage return from string. Everything I have tried so far
hasn't worked though. Does anybody have a snippet which might be able
to show me how to do this?

Where are you getting the string and what have you tried to remove it?

This will remove the CR/LF at the end of the text of any selected shape:

With ActiveWindow.Selection.ShapeRange(1).TextFrame.TextRange
' If the rightmost two characters are CR, LF
If Right$(.Text, 2) = vbCrLf Then
' Use the entire string MINUS the rightmost two characters
.Text = Left$(.Text, Len(.Text) - 2)
End If
End With

In use, you'd want to add more tests/errorhandling to ensure that you don't try
to invoke this on a shape that has no text frame.
 
T

Troot

hi Steve,

thanks for answering. I'm taking the value from the notes pane, doing
some processing on it (trying to use it as something like an ini file)
and then writing back to it. But in the processing I'm putting vbCrLf's
into it. But I don't want any trailing or leading newlines. I took your
code (I think the problem was I forgot an crlf is 2 chars) and did
this:
' If the rightmost two characters are CR, LF
While Right$(new_notes_val, 2) = vbCrLf
' Use the entire string MINUS the rightmost two characters
new_notes_val = Left$(new_notes_val, Len(new_notes_val) - 2)
Wend

While Left$(new_notes_val, 2) = vbCrLf
new_notes_val = Right$(new_notes_val, Len(new_notes_val) - 2)
Wend

That seems to be working now ;o)

Thanks again
John
 
Top