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 -
I used sanitizedText = Replace(Selection.Text, Chr(13), "")
successfully; 13
is the ASCII value for 'carriage return'.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With