1

I'm creating a series of tags in Illustrator, using VBA in excel (the excel worksheet has the information that populates the tags), and I cannot find a way to specify that the font which appears in Illustrator is italicized and a particular font.

Using:

.TextRange.CharacterAttributes.TextFont = appIll.TextFonts.Item("Arial") 

lends the same result as using:

.TextRange.CharacterAttributes.TextFont = appIll.TextFonts.Item("Monotype Corsiva")

And needless to say, I also can't get italics. I'm very new to this, but would appreciate anyone letting me know how to specify the font and font-style. Thanks!

            .TextRange.ParagraphAttributes.Justification = aiCenter
            .TextRange.CharacterAttributes.size = dblTopLine1FontSize
            .TextRange.CharacterAttributes.StrokeWeight = 0.35
            .TextRange.CharacterAttributes.StrokeColor = clrStrokeColor
            .TextRange.CharacterAttributes.FillColor = clrFontFillColor
            SetItalics tfrmTopLine1
            .CreateOutline
        End With
Lara Klopp
  • 13
  • 2
  • This is a shot in the dark but rather than `TextFonts.Item("..")` try `TextFonts.name = 'Arial'` and `TextFonts.style = 'italic'` – wahwahwah Nov 18 '14 at 21:45
  • Maybe worth checking if italic, bold etc. are actually fonts in their own right? eg Times, TimesBold, TimesItalic and the like. Perhaps explore the TextFace(s) property/collection? – barryleajo Nov 18 '14 at 23:43
  • I've tried everything ... I could fill a page with lines of what I've tried. I just tried "TextFonts.name etc" and no dice, wahwahwah, but thank you for the suggeston! barryleajo, they might be, and that would be something I hadn't tried (though I've tried Arial-Italic, and Arial Italic), but that even if I just have the main name of a font that I know is in both applications, like Monotype Corsiva, nothing changes the default (?) setting. So if I could change the font but not get italics, I'd be focused on that, but I can't even change the font. – Lara Klopp Nov 19 '14 at 01:08

1 Answers1

0

have a look at the following to see if it helps:

Firstly, at the risk of stating the obvious, I first identified that the font I 'needed' to use was indeed accessible to my copy of Illustrator - as it happens, to use Monotype Corsiva in code it has to be "MonotypeCorsiva"! The lessons here are that the 'real' font name may be different from the Illustrator displayed font name and the 'real' font name also indicates the 'style'. I used the following code which simply listed the font and its 'style' to Excel's Immediate Window. Illustrator needs to be open for this example.

Sub IllFnts()
Dim IApp As New Illustrator.Application
Set IApp = GetObject(, "Illustrator.Application")

Dim fnt As Illustrator.TextFont

    For Each fnt In IApp.TextFonts
        Debug.Print fnt.Name & "  -  " & fnt.Style
    Next
End Sub

I then added a Point Text Frame, added some text and changed the TextFont with the code below:

EDIT - UPDATE TO INCLUDE A MEANS OF APPLYING ITALIC

Sub TestChngeFnt()
Dim IApp As New Illustrator.Application

    If IApp Is Nothing Then
        Set IApp = CreateObject("Illustrator.Application")
    Else
        Set IApp = GetObject(, "Illustrator.Application")
    End If

Dim fnt As Illustrator.TextFont

'A distinctive font for reference?
Set fnt = IApp.TextFonts("Algerian")

'Add a Document
Set docRef = IApp.Documents.Add()

'Add some Point Text
Set pointTextRef = docRef.TextFrames.Add()
pointTextRef.Contents = "Some Text in a Point TextFrame"
pointTextRef.Top = 700
pointTextRef.Left = 20
pointTextRef.Selected = True
pointTextRef.TextRange.CharacterAttributes.Size = 35
IApp.Redraw

'Set distinctive font
IApp.Documents(1).TextFrames(1).TextRange.CharacterAttributes.TextFont = IApp.TextFonts.Item(fnt.Name)

MsgBox "Have a look at the text font before changing to another."

'set a new font to 'regular'
Set fnt = IApp.TextFonts("BodoniMT")
IApp.Documents(1).TextFrames(1).TextRange.CharacterAttributes.TextFont = IApp.TextFonts.Item(fnt.Name)

MsgBox "New text font before changing to italics."

'set font to 'italics' within the same font family?
Set fnt = IApp.TextFonts("BodoniMT-Italic")
IApp.Documents(1).TextFrames(1).TextRange.CharacterAttributes.TextFont = IApp.TextFonts.Item(fnt.Name)


End Sub

This example includes a couple of message boxes to pause the code to observe the text changes. Applying 'italic' in this example is really selecting a font from the same font family designed as italic? Not completely sure if this is the 'correct' approach with Illustrator or just a workaround,but it may take you forward a little.

You may also find this Adobe Illustrator CS5 Scripting Reference: vbScript useful although the Object Browser in Excel is also a good starting reference.

barryleajo
  • 1,956
  • 2
  • 12
  • 13
  • Wow, thank you so so much! I wish I could up-vote you, but I don't have a high enough score yet. I don't even know if that's going to work, but you put so much effort into answering I'm equally grateful either way. I'm going to go try that now. – Lara Klopp Nov 20 '14 at 22:30
  • Thanks Lara I too learnt quite a bit about Illustrator with your Q. If this answers your Q perhaps you would accept it as Answer to close off the thread. – barryleajo Nov 20 '14 at 22:33
  • Oh, rats. I mean, the msgboxes worked, and the creation of the new Illustrator document worked, but all 3 fonts - the first, the second, and the italic, were all Myriad Pro. My computer is apparently obsessed with Myriad Pro, that's all there is to it. Thank you so much for your help, though! I greatly admire your coding ability, and I'm sure this works on everyone else's computer. I wish I knew why mine is different. – Lara Klopp Nov 20 '14 at 22:45
  • Oh, and the italic wasn't actually myriad pro italic, it was just myriad pro. But the code that i originally used worked to create a font on someone else's computer, so there's something about mine that's different. – Lara Klopp Nov 20 '14 at 22:49
  • Did you check that 'my' fonts were actually available to your copy of Illustrator by running the first code Sub? If not choose any fonts available to yours and type them correctly into the code. Note, don't use the display name! – barryleajo Nov 20 '14 at 22:50
  • Oh, ok, that did it! Even though my version of Illustrator lists Arial, and Arial-Italic, it wasn't reading them as valid fonts. You're awesome, thank you so much! I'll accept this as answer. I still wonder why my copy of Illustrator says it has fonts which it then doesn't recognize, but that's not my main concern at the moment. Thanks again! – Lara Klopp Nov 20 '14 at 23:28
  • I think I closed this ... I checked the green arrow ... does that do it? Can I ask one more question, you've been so helpful. I did enter fonts that were in my version of Illustrator (which your fonts weren't), but even though they were listed in Illustrator, they came up as not recognized. I used trial-and-error to find ones that worked with the program. Would you know why? – Lara Klopp Nov 21 '14 at 00:06
  • Thanks for accepting my answer. This just indicates to others that the Q has been answered/accepted. I don't really use Illustrator much but I am seeking to write a particular script shortly so I am happy to help where I can. Suggest you open another question and then other expertise may be able to help also and perhaps more quickly. Oh and mention if you are using a Mac or not. By the way mine is just a bog standard install with standard fonts that shipped with Illustrator - where are you located - there may be differences in different countries? – barryleajo Nov 21 '14 at 07:46