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 -
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.
(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.)
You should use
ChrW$()
for unicode characters:Or, if the paragraph mark is always at the end maybe you can just remove the last character using
I used
sanitizedText = Replace(Selection.Text, Chr(13), "")
successfully;13
is the ASCII value for 'carriage return'.