Skip to main content
Inspiring
February 28, 2022
Answered

VBA code to place image in AI

  • February 28, 2022
  • 1 reply
  • 958 views

Hi, I am trying to place objects (some img files) in an illustrator file, using VBA/excel.

filePath = ActiveWorkbook.Path
Set appRef = CreateObject("Illustrator.Application")
Set docRef = appRef.Open(filePath & "\test.AI")
Set placedItem = docRef.placedItems.Add()
'placedItem.File = File("\test.png")

 

The code up to appRef.Open(path) works - it opens the illustrator file.
But I cannot figure out how to use placeditems.Add(), or whatever necessary to place the image.

 

This topic has been closed for replies.
Correct answer CarlosCanto

for svg and probably dxf, use the Group's CreateFromFile method

 

Set igroup = docRef.GroupItems.CreateFromFile("C:/Users/Canto/full path to your file.svg")

1 reply

emosmsAuthor
Inspiring
February 28, 2022

This code works:

Dim filePath As String
filePath = ActiveWorkbook.Path
Set appRef = CreateObject("Illustrator.Application")
Set docRef = appRef.Open(filePath & "\5x10_NEW.AI")
Set placedItem = docRef.placedItems.Add()
placedItem.File() = filePath & "\_QR\123.jpg"

 

Now I have a problem placing .svg graphics.

I am trying to automate a very tedious task of manually placing a lot of different .svg files.
I do that manually (file/place/.svg images), but when I use placedItems.Add(), there is an error, that the format cannot be accepted 😞

emosmsAuthor
Inspiring
February 28, 2022

Cannot work with .dxf as well.
It works ok when I place .dxf manually.

 

Could it be that it cannot work with vector graphics?
Mby I have to scale the graphics first to some dimensions?