Skip navigation
Currently Being Moderated

Illustrator VBA scripting 101 - via Excel

Mar 17, 2012 12:23 PM

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?

 
Replies
  • Currently Being Moderated
    Mar 17, 2012 12:58 PM   in reply to CarlosCanto

    That is a great start Carlos! I'll give it a go and let you know. Thanks!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 17, 2012 3:29 PM   in reply to duhwellhuh

    Carlos- I tested this and got it to work. I'm a little familiar with VBA in Excel within Excel and that is it. That is sort of what  got me into scripting. I started messing around with JS because it was cross-platform. I understand that DIM is the same as VAR in JS and that SET adds a reference to the object. I also understand that "set object = nothing" frees up memory, correct? With that said, I know you don't want to move too fast with my 101, but I have a question.

     

    In my last discussion about getting illustrator to read from an excel csv, I was wondering if the same thing could be done with Excel.

     

    Could an XLSM file read a line from a CSV file in "A1" and depending on what was in the first column in the XLSM, search the CSV file and find the indexed item in the second column or third? I've done it before with standard VLookup functions and it was cumbersome and very slow, and for some reason, everytime I would save the file it would take forever although the xls file was a single sheet.

     

    i've attacthed a sketch of what I'm talking about, because it's hard to explain and I think the sketch explains it better. Here it is, sorry if it is blurry, it looked fine before I posted:

    xlsm example.PNG

     

    I apologize to ask a non-Adobe question on their forum, but you are a big help and the guys I've come across on Excel forums have been very condesending. I'll eventually get to the step of saving to ADOBE PDF from Excel, but not just yet. Thanks in advance!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 17, 2012 4:35 PM   in reply to CarlosCanto

    k Carlos, will do!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2012 4:51 AM   in reply to CarlosCanto

    When can we expect the next class session to begin?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2012 2:20 AM   in reply to CarlosCanto

    Excellent lesson Carlos! I've been trying to get my head around alignment for awhile.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 24, 2012 3:55 AM   in reply to CarlosCanto

    Excellent, I didn't know that about the origin reversing. That's odd.Thanks

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2012 5:01 PM   in reply to duhwellhuh

    Anymore Carlos, my brain is hungry!!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 30, 2012 7:01 AM   in reply to CarlosCanto

    No problem, I love to learn.

     

    Yeah, I haven’t seen you on any posts lately. I was wondering what happened. Hopefully you were writing a how to book. ☺

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 6:07 AM   in reply to CarlosCanto

    Oh, that’s a good lesson. Thanks a lot for this one! I wish there was a way for me to give you points on this forum.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 10, 2012 2:35 AM   in reply to CarlosCanto

    Hey Carlos-

     

    I have a grasp on the shapes above, but how about drawing shapes from points? I've went through some tutorials that came with Illustrator VBScript, and I've figured out how to get the sizes right, but when I try to position them, the values that Illustrator show are wrong when I use methods lIke .top and .left for the x and y coordinates. I would assume that it would be an array, but is there a quick way to absolute reference where you want to draw something?

     

    If you have this saved for a future lesson, I can wait, no problem. thanks

    
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 3:34 PM   in reply to CarlosCanto

    Got anymore Carlos?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 21, 2012 3:47 PM   in reply to CarlosCanto

    Alright Carlos. I eagerly await your next lesson!

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 22, 2012 3:44 PM   in reply to CarlosCanto

    note that the top/left values don't match exactly with the values we entered (200, 200), homework, can you tell why?

     

     

    Is that because the shape was drawn with the default 1 pt stroke and the .top & .left values are based on visible Bounds?  (my only guess)  So why is that?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)