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?
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.
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
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
Copy link to clipboard
Copied
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