May 16 2023 09:55 AM - edited May 16 2023 10:32 AM
Hello. If you have a minute, I'm extracting text from a range within MS Word...for example...
targetRange.Start=200
targetRange.End=500
This returns all the text (targetRange.Text) but since unformatted (although line returns seem to be preserved), all numbered list labels (1,2,3...a, b, c sublists, etc) within the Range are stripped. Is there a way to preserve all the list designations within the text when setting a Range object? Tried targetRange.FormattedText but that doesn't seem to make a difference. thank you.
May 16 2023 01:00 PM
@Tom_Griffith What do you want to do with the range?
May 17 2023 01:53 AM
You can retrieve the formatted text from a range. However, as Doug wrote, making a suggestion would be a lot easier if we knew exactly what you are trying to accomplish with your macro.
May 17 2023 10:22 AM
May 17 2023 10:23 AM
May 17 2023 01:10 PM
May 17 2023 01:48 PM
May 17 2023 02:51 PM
@Tom_Griffith Either use Undo, or close the document without saving it.
May 18 2023 08:57 AM - edited May 18 2023 09:06 AM
Thanks again for your help on those two methods. I decided on the following (pseudo code.)
wordDoc.ConvertNumbersToText
var action_text=actionRange.FormattedText;
wordDoc.Undo
action_text=action_text.raplace(/\t\/," ")
...do insert stuff with action_text....
I was hoping to do a more precise Find.Execute on the Range to get rid of only the tabs inserted (number+tab+text) by ConvertNumberToText but I guess I'll live with a global tab replace on the text object (action_text) created from the Range. It'll dump any other tabs user may have put in but i think that'll be ok. I think doing any additional stuff after ConvertNumbersToText, like the Find.Replace, will shove the ConvertNumbersToText out as the Undo target. Thanks so much again.
May 18 2023 01:23 PM
@Tom_Griffith Use
With ActiveDocument
.UndoClear
.ConvertNumbersToText
Selection.Range.Text = Replace(Selection.Range.Text, vbTab, " ")
'do what you want to
.Undo (3) 'may need to replace 3 to allow for other changes that you make
End With