• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
4

Illustrator VBA scripting 101 - via Excel

Community Expert ,
Mar 17, 2012 Mar 17, 2012

Copy link to clipboard

Copied

This post will attempt to introduce newcomers to Illustrator Visual Basic Scripting (well, not actually vbs, but rather tru VBA, Visual Basic for Applications). I personally prefer vba over bvs for a number of reasons. First, I always have Excel and Illustrator open, so it makes sense for me use it to drive Ai. Second, I usually need to transfer data between the two programs. Third...I love the Excel IDE...ok, let's get right into it.

- Open Excel

- hit Alt+F11, to bring up the editor

- in the Tools menu, click on References...

- add a reference to "Adobe Illustrator CS5 Type Library"

- in the Personal.xls (or in any other book) add a Module. Personal is a global workbook that is always available. If you don't see it, go back to Excel and record a macro, anything will do. That will create the Personal file.

- and type the following in that module

- we have to continue the tradition and do the "HelloWorld" script

Sub helloWorld()
    Dim iapp As New Illustrator.Application
    Dim idoc As Illustrator.Document
    Dim iframe As Illustrator.TextFrame
   
    Set idoc = iapp.ActiveDocument
    Set iframe = idoc.TextFrames.Add
   
    iframe.Contents = "Hello World from Excel VBA!!"
   
    Set iframe = Nothing
    Set idoc = Nothing
    Set iapp = Nothing
End Sub

- save Personal book

- open Illustrator and create a new document first

- to run, move the cursor anywhere inside the Sub...End Sub and hit F5

that's it for now...in the following posts we'll move the text to the middle of the page, create new documents, get data from an Excel Range to Illustrator, get data from Illustrator text frame to an Excel Range...and more, hopefully.

questions? comments?

TOPICS
Scripting

Views

33.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jun 22, 2016 Jun 22, 2016

Copy link to clipboard

Copied

I'm assuming the height of the container is fixed, so get the width of the Text frame, compare it to the height of the container, if bigger then resize your text frame to the maximum width that will fit within the container.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

hello, when I do all that i have an error which says "ActiveX component can't create object or return reference to this object (Error 429)"  and it brings me to that line "Set idoc = iapp.Documents.Add" . I'm not a programmer at all and using the last version of illustrator. Could you help me please ? CarlosCanto

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 27, 2021 Aug 27, 2021

Copy link to clipboard

Copied

Sorry for bumping such an old post.

 

I have good vba skills and have created illustrator code before but never used the layers really. 

 

@CarlosCanto I am trying to get into the layers in illustrator. I can select the parent layer but how do i go deeper into the sublayers contained in that layer?

 

I've tried everything.

 

Thanks in advance

 

Euan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 28, 2021 Aug 28, 2021

Copy link to clipboard

Copied

LATEST

to access sublayers you just have to chain commands (using dot notation) 

 

for example, to get the width of the first item in the first sublayer of the first layer

msgBox Illustrator.Application.ActiveDocument.Layers(1).Layers(1).PageItems(1).width

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines