Remove paragraph mark from line

I have a macro that finds all the heading styles 1 in my document and lists them in a ComboBox in UserForm.

My problem is that the search routine that I use also selects the paragraph mark ( ΒΆ ) after the text I want to copy and which appears in the ComboBox.

How to remove this from a string? I tried using replace() , replacing vbCrLf , vbCr , vbLf , vbNewLine , ^p , v , Chr(244) and Asc(244) with "" , but nothing worked, For example -

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

Can anyone help with this issue? Thanks.

This is what my form looks like -

enter image description here

+6
source share
3 answers

You should use ChrW$() for Unicode characters:

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

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

 myString = Left(myString, Len(myString) - 1) 
+9
source

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

+4
source

This tiny script replaces a piece of text that is highlighted in a document (for example, marked with a cursor) with dashes at the beginning of the line. He replaces them with an improvised marker point: (o)

the script searches for the paragraph parameter followed by a hyphen entries.

I had a similar problem as in the question above, since I was sure that the paragraph labels should be "Chr (13) and Chr (10)", which is equal to "VbCrLF", which is equal to "Carriage return, line feed" " However, β€œChr (13) and Chr (10)” were wrong. 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 to adjust the text written in Word to the insanely limited character set of the official application form for the Erasmus + European Union program to promote continuous learning. Well, I learned something.)

0
source

Source: https://habr.com/ru/post/977416/


All Articles