Unless I am wrong you have to name the font specifically like "Arial Bold". If you intend to use a font that has no Bold face, it won't work.
there are in fact two properties like
fontFamily and fontStyleName but they are read-only.
Thanks. I've seen scripts with statements like
myText.fontStyle = "Bold";
The font being used does have a bold font style available. I'm having difficulty, apparently, identifying the "text object" that will receive the formatting. Another simple way to insert text at the insertion point is:
myText = "Anticipated Responses: "
app.selection.contents = myText
But still can't figure out how to incorporate the fontStyle.
1 person found this helpful
The "contents" of a paragraph is not an InDesign Text object, so you cannot apply formatting to it. Try this:
myText = "Anticipated Responses:"; insertionPt = app.selection.paragraphs; insertionPt.insertionPoints.contents = myText; insertionPt.characters.itemByRange(insertionPt.characters, insertionPt.characters[myText.length-1]).fontStyle = "Bold";
-- that way you set the font style of actual InDesign text.
(Why the workaround using a variable? I tried too quickly to get a result but ID formatted the wrong text. I think "app.selection" gets messed up because you are adding characters. This was the first thing that worked. Well, sometimes, that's all that's necessary.)
(Sorry, Loic. Nothing wrong with "fontStyle" -- that is, if the style is available for the font, of course.)
No offense Theunis
Good if our friend could find answer thanks to you
The code works, so thanks much for that.
However, I should have mentioned that this will typically be inserted in a table cell.
The code works outside of a table but throws an error when the insertion point is in a cell.
It runs exactly the same for me. Wait ... is that in an empty cell?
An empty cell doesn't contain any paragraphs, so the insertion point of the first one doesn't exist either. A small amendment (and it won't win the price for beautiful code, but hey! it works):
myText = "Anticipated Responses:"; if (app.selection.paragraphs.length == 0) app.selection.contents = myText; else app.selection.paragraphs.insertionPoints.contents = myText; insertionPt = app.selection.paragraphs; insertionPt.characters.itemByRange(insertionPt.characters, insertionPt.characters[myText.length-1]).fontStyle = "Bold";
Thank you so much. Done some vba stuff in Word but still floundering in