Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove paragraph mark from string

I have a macro that finds all of the 'Heading 1' styles within my document and lists them in a ComboBox on a UserForm.

My problem is that the Find routine I am using is also selecting the paragraph mark () after the text I wish to copy, and that is being displayed in the ComboBox.

How can I remove this from the string? I've tried useing replace(), replacing vbCrLf, vbCr, vbLf, vbNewLine, ^p, v, Chr(244) and Asc(244) with "", but nothing has succeeeded. For example -

sanitizedText = Replace(Selection.Text, "^v", "")

Can anyone please help with this problem? Thanks.

Here is how my form looks -

enter image description here

like image 753
David Gard Avatar asked Oct 29 '14 15:10

David Gard


2 Answers

I used sanitizedText = Replace(Selection.Text, Chr(13), "") successfully; 13 is the ASCII value for 'carriage return'.

like image 165
Draig Hodge Avatar answered Oct 06 '22 01:10

Draig Hodge


You should use ChrW$() for unicode characters:

sanitizedText = Replace(Selection.Text, ChrW$(244), "")

Or, if the paragraph mark is always at the end maybe you can just remove the last character using

myString = Left(myString, Len(myString) - 1)
like image 29
Miguel Febres Avatar answered Oct 06 '22 00:10

Miguel Febres