VBA Word - Trim trailing white space from a Range.FormattedText
I have a macro which does almost all of what I want, except that the text it generates may have unwanted trailing white space. I am using Range.FormatedText to preserve italics, bold, etc, and I can't work out how RTrim() a Range.FormattedText.
Dim oRng As Range
Dim oNewRng As Range
Set oRng = Selection.Range '(the formatted range you are wanting to write)
oRng.MoveEndWhile Chr(32), wdBackward 'Remove trailing spaces from the range
Set oNewRng = ActiveDocument.Range 'Locate the range where it is to be written
oNewRng.Collapse wdCollapseEnd
oNewRng.FormattedText = oRng 'then write it.
Graham Mayor (Microsoft Word MVP 2002-2019) For more Word tips and downloads visit my web site https://www.gmayor.com/Word_pages.htm
3 people found this reply helpful
·
Was this reply helpful?
Sorry this didn't help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.