使用VBA从Excel电子表格格式化Illustrator中的斜体

我在Illustrator中创build了一系列标签,在excel中使用VBA(excel工作表包含填充标签的信息),而且我无法find指定在Illustrator中显示的字体是否以斜体字显示的方式。

使用:

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

借用与使用相同的结果:

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

不用说,我也不能得到斜体。 我对此很新,但希望任何人知道如何指定字体和字体样式。 谢谢!

  .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 

看看下面看看是否有帮助:

首先,冒着显而易见的风险,我首先确定了我需要使用的字体的确是我的Illustrator副本可以访问的 – 碰巧,在代码中使用Monotype Corsiva必须是“ MonotypeCorsiva ”! 这里的教训是“真正的”字体名称可能与Illustrator显示的字体名称不同,“真正的”字体名称也指示“样式”。 我用下面的代码简单地列出了字体和它的样式到Excel的立即窗口。 Illustrator需要为这个例子打开。

 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 

然后我添加了一个点文本框架,添加了一些文本,并用下面的代码改变了TextFont:

编辑 – 更新包括应用意大利语的手段

 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 

这个例子包括几个消息框来暂停代码来观察文本的变化。 在这个例子中应用“斜体”确实是从相同字体系列中select一种字体devise为斜体? 不完全确定这是Illustrator的“正确”方法,还是仅仅是一种解决方法,但是可能会让您稍微前进一点。

您也可以find这个Adobe Illustrator CS5脚本参考:vbScript有用,虽然在Excel中的对象浏览器也是一个很好的起始参考。