• 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

35.2K

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
Engaged ,
Sep 25, 2013 Sep 25, 2013

Copy link to clipboard

Copied

Sorry - forgot point #2.   Do you have any experience in Visual Basic? If so, while it could be considered a "one-off" way to get to Illustrator scripting, Visual Studio/VB does provide Intellisense for the entities that should help you in your learning process. I am not sure what Visual Studio Express provide in the way of Intellisense, but at least the Pro version does. I would like to think that even the Express version would do the trick for you. My thinking had always been that sInce you have to have Excel open to run VBA anyway, may as well have Intellisense and a top-rate debugger to help you. Now having said all of that, if Excel/VBA offers intellisence, then there may not be much of an advantage to many, but I find that working in VB gives me a whole new level of control outside of AI scripting that I can use to integrate with the AI scripting.

JMHO.

Take care,

TT

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 ,
Sep 25, 2013 Sep 25, 2013

Copy link to clipboard

Copied

hi TT thanks for commenting, VBA does have intellisence and code completion. VBA is nice, easy to use and "on-hand" in most office environments to get people introduced to programming...

...if the script runs without a document open, it will raise a "no such element" error, it seems tyedye is having issues connecting Excel to Illustrator

tyedye, try this, close Illustrator, then go to your Illustrator Shortcut, right-click on it and click on "Run as administrator"...then try running you VBA code.

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
Guest
Sep 26, 2013 Sep 26, 2013

Copy link to clipboard

Copied

Thank you for the quick responses TT and Carols. I really appreciate that.

I still cannot get this thing running. Yes I have created a blank document in Illustrator. I would just goto File ->New and use the default settings to create a new document, the default settings selected were the Print Profile (I dont know if that makes a difference or not). Is there anyway that I would have to make a new document active? I know in excel just having it open means it is active correct?

Carlos, I tried the Run as Administrator and as soon as I read that I thought that could do the trick, but nope, same thing. Also, I realized that I have both a 32bit and 64bit version of Illustrator, so I tried it in both versions as administrator, still same error. Both versions of Excel are 32bit and I had read that the 64bit versions were lacking in some of the VBA stuff so I think I should be safe there. On a side note I tried the other code you posted on the other forum regarding translation (post 11 of http://forums.adobe.com/thread/773143) after creating a document with those few text layers and the same error came up on the same line of code (Set idoc = iapp.ActiveDocument).

TT, although I said I am a beginner to VBA, that might not be entirely true, but I like to error on the side of more beginner because my experience has more to do with editing code other people have previously made than actually making it from scratch myself.

Any other recommendations?

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 ,
Sep 26, 2013 Sep 26, 2013

Copy link to clipboard

Copied

try removing the reference to the Illustrator Type Library, run as administrator, then re apply the Type Library

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 ,
Sep 26, 2013 Sep 26, 2013

Copy link to clipboard

Copied

how about this test, does it run?

Sub basicTest()

    Dim iapp As New Illustrator.Application

    MsgBox iapp.Name

End Sub

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
Guest
Sep 26, 2013 Sep 26, 2013

Copy link to clipboard

Copied

I tried removing and reapplying the Type Library, still did not work. I tried elevating the Illustrator library as well but that didnt do anything.

I just tried this basic test and it still does not work, same error, but it occurs on:

MsgBox iapp.Name

I tried running Illustrator in compatibility mode and I got a different error when I did that:

Run-time error '-2147024156 (800702e4)':

Automation error

The requested operation requires elevation.

When I run the script, if I have windows open on top of Illustrator, those windows dissapper and it looks as though the computer just stops on Illustrator for about 30 seconds until the Error comes up.

I thought perhaps it could be Avast! Antivirus blocking any scripts trying to run, so I turned everything off (while not connected to any networks) and tried to run the script and same ol Error 429 ActiveX Error. I dont have any other ideas besides doing another fresh install of office and CS6 on another HD but I really dont want to do that.

Any other ideas?

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
Engaged ,
Sep 26, 2013 Sep 26, 2013

Copy link to clipboard

Copied

tyedye09wab,

I (probably we) applaud your persistence. Don't give up. It will be worth your while. We've all been through it to one degree or another.

I don't have a lot of experience in VBA to help you here too much, although (and Carlos will be REALLY excited about this since he's been trying to recruit me to this platform for sometime ) I actually did do a real fast setup with VBA in Excel to Illustrator and it was pretty much a cakewalk. I know that might not be exactly what you wanted to hear, but it goes to prove that it IS doable. I even googled some 429's for you but what I found was more for Office 2007 and prior, so probably not much help there.

Again - here is just a thought (because we REALLY want to see you get past this) -- I wonder if you have any other CS6 components (like InDesign) that you could just reference the type library for that and give the old "Hello World" one more college try. If that were to work, maybe it is a corrupted CS6 Illustrator type library. Just thinking...

HANG IN THERE!

TT

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
Guest
Sep 26, 2013 Sep 26, 2013

Copy link to clipboard

Copied

Thanks TT. Im really trying and I want this to work...I think I've given it more that the "good ol college try" but I will press on.

It seems to be something on the Adobe side of things, and Im wondering if I didnt install all of the features or something originally.

When I looked at photoshop (again I know this isnt Illustrator, but maybe there are differences between CS5 and CS6 we are not taking into account) there was this little article that mentioned CS6 not having some of the plugins that were previously available in CS5 and earlier. Is it possible I need to install some kind of add on to Illustrator?

http://helpx.adobe.com/photoshop/kb/plug-ins-photoshop-cs61.html#id_14532

Thanks again,

TyeDye

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
Engaged ,
Sep 26, 2013 Sep 26, 2013

Copy link to clipboard

Copied

I don't think so. At quick glance it looks like it has something to do with TWAIN drivers. I think that we will find it to be something simple. Problem is, finding the simple solution sometimes takes way longer than it should. I'll keep thinking...

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 ,
Sep 26, 2013 Sep 26, 2013

Copy link to clipboard

Copied

it supposed to be as simple as I described it in post #1,

if you have other Office Applications try making a simple application.name test from Excel to Word or Outlook, if that works then Office installation is ok and you may need to reinstall Illustrator with antivirus off...just a thought.

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
Guest
Oct 03, 2013 Oct 03, 2013

Copy link to clipboard

Copied

Carlos,

I dont know exactly what you mean when you say a simple application.name test from Excel to Word or Outlook. Do I have to open a reference library like adobe products?

Could you give me a simple sample code to try with excel and word?

TyeDye

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
Guest
Oct 23, 2013 Oct 23, 2013

Copy link to clipboard

Copied

HELLO AGAIN!

So I am pretty excited because I finally got it working!

I had to do a clean install of Windows and so I tried it out as soon as I installed CS6 before updating anything (including Windows Updates) and it seems that the error I got regarding the ActiveX Component only occurs in 64bit Illustrator while the 32 bit Illustrator works fine. I had tried the 32bit version on my other hard drive and had tried this without getting it, but for some reason it works on the cleaner install. I am using Excel 2013.

I am running Windows 7 Pro SP1 64Bit

8GB RAM

Intel i7 @2.90GHZ

I still have my older HD, but do not currently have access to it so I will try what I just did later and keep you all updated...Im excited that I am back in the game!

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
Engaged ,
Oct 23, 2013 Oct 23, 2013

Copy link to clipboard

Copied

Great, tyedye09wab! We've been waiting for this good news email! I might suggest that you start a new thread if you have any further problems, just to keep this one less contaminated and folks will be able to focus on your new problems, if any. Anyway - welcome back -- and congrats on your persistence. -TT

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 ,
Oct 23, 2013 Oct 23, 2013

Copy link to clipboard

Copied

indeed good news, thanks for posting your findings...could it be possible the 64 bit version has its own Type/Object Library?

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
Explorer ,
Jun 17, 2015 Jun 17, 2015

Copy link to clipboard

Copied

Hi Carlos & Group,

I couldn't do the fourth step

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"

ToForumVBJPG.JPG


In Tools ->References I couldn't find this library.

How to proceed further?



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
Explorer ,
Jun 17, 2015 Jun 17, 2015

Copy link to clipboard

Copied

Got it working sorry please ignore my last post I was trying on a machine which doesn't have Adobe Illustrator installed....

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
Guest
Sep 09, 2015 Sep 09, 2015

Copy link to clipboard

Copied

Hi Carlos,

Is there anyway we can get the Illustrator alphanumeric data to excel.Suppose my illustrator file has call outs in the .ai file can i get them in to excel sheet

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 ,
Sep 09, 2015 Sep 09, 2015

Copy link to clipboard

Copied

Hi, yes it's possible, see Lesson 4, post # 15

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
Guest
Sep 10, 2015 Sep 10, 2015

Copy link to clipboard

Copied

Hi Carlos,

Good Afternoon,

Thanks for the quick reply.

Can i have the code to read the text available and write it to excel .Please support me on this.I need the code as i am working on a model here where all the illustrator call outs are listed in a excel to find out missed and repetitive call out or i need a script which converts .ai file to text .txt file.

Your help is highly appreciated.

It would be great if i get the code today by EOB hours.

Thanks and regards,

Bhanu

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
Valorous Hero ,
Sep 10, 2015 Sep 10, 2015

Copy link to clipboard

Copied

I think this post was meant to be a lesson on how to build your own code to accomplish your goals. For instant code to solve your problem, may I kindly suggest posting the question on the Adobe Freebie Script forum, the forum which is identical to this one, but where dozens of developers who are wealthy and retired, sit around all day to provide pro bono answers to anyone who asks. Caveat emptor: this forum may be difficult to locate.

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 Beginner ,
Oct 17, 2015 Oct 17, 2015

Copy link to clipboard

Copied

How can i change a  frame text that already exists.

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 ,
Oct 17, 2015 Oct 17, 2015

Copy link to clipboard

Copied

get a reference to text frames by index number, get the first Frame

Set iframe = idoc.TextFrames(1)

change contents

iframe.Contents = "Hello World from Excel VBA!!"

also, you could get a reference to Named text frames like this

Set iframe = idoc.TextFrames("frame2")

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 Beginner ,
Jun 22, 2016 Jun 22, 2016

Copy link to clipboard

Copied

Hi Carlos,

Thx a lot,

Can you help me again?

How can I fix this problem ?, the text is more larger than contents. 

imagem.JPG

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 ,
Jun 22, 2016 Jun 22, 2016

Copy link to clipboard

Copied

two options, make the text smaller, or make the container bigger.

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 Beginner ,
Jun 22, 2016 Jun 22, 2016

Copy link to clipboard

Copied

Yep,

But, There are same way to do this using illustrator´s DLL ?

Compare Text and Container, if necessary do somethig.

Thanks

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