OK I see I can do this
inDesignApp.Selection = para.Characters.ItemByRange(1, 1)
inDesignApp.Selection.Item(1).appliedCharacterStyle = mycharstyle
But is there anyway I can peek at the contents of this Selection? Or the contents of whatever "ItemByRange" returns? I need to apply a format only to numbers. But I can't find a way to actually look at the text/contents/characters using this selection method.
OK got it. I can peek at para.contents.tostring
How can I select a substring of text from my Cell, so that I can apply a character style?
This works fine when I'm only selecting a single character:
If IsNumeric(para.Contents.ToString.Substring(0, 1)) doc.Selection = para.Characters.ItemByRange(1, 1) doc.Selection.Item(1).appliedCharacterStyle = mycharstyle End If
but it fails if I try to select a range of characters
doc.Selection = myCell.Characters.ItemByRange(72, 76)
The error is
Invalid valid for set property 'Selection. Expected Array of Objects, Object or idNothingEnum enumerator, but received (Character, Character, Character, Character, Character)
I think there must be some entirely different technique to apply my CharacterStyle to a substring of text in my Cell, but after searching high-and-low I've yet to discover it.
.itemByRange() gives you an array of objects.
.appliedCharacterStyle should work with this but
.docSelection fails, I guess.
There is no way to select a few "uncontinuos" text objects at once.
Skip setting .selection. Use .appliedCharacterStyle directly to .itemByRange.