Remove paragraph mark from string

14,782

Solution 1

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)

Solution 2

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

Solution 3

This tiny script replaces, in a piece of text selected in the document (i.e. marked using the cursor) hyphens that are at the beginning of a line. It replaces them by an improvised bullet point: (o)

The script searches for occurances of "Paragraph mark followed by hyphen".

I had a similar problem as in the question above, as I was sure paragraph marks should be 'Chr(13) & Chr(10)', which is equal 'VbCrLF', which is equal 'Carriage Return, Line Feed'. However, 'Chr(13) & Chr(10)' were wrong. The naked Chr(13) did the job.

Sub MakeAppFormListPoints()

'Replace list hyphens by (o)

   Dim myRange As Range
   Set myRange = Selection.Range   'What has been marked with the cursor

      Debug.Print myRange  ' Just for monitoring what it does

   myRange = replace(myRange, Chr(13) & "-", Chr(13) & "(o)")

      Debug.Print myRange  ' Just for monitoring what it does

End Sub

(I use this for adjusting text written in Word to the insanely restricted character set of the official application form for the European Union Erasmus+ programme to promote lifelong learning activities. Well, I learned something.)

Share:
14,782
David Gard
Author by

David Gard

Updated on June 05, 2022

Comments

  • David Gard
    David Gard almost 2 years

    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

  • David Gard
    David Gard over 9 years
    As mentioned in the question comments, the second of your suggestions here is working just fine for me. Thanks for your help.