VBA 循环填充 Illustrator 模板文字层
'定义Illustrator变量 Dim aiApp As Illustrator.Application Dim aiDoc As Illustrator.Document Dim aiLayer As Illustrator.Layer Dim aiTextItem As Illustrator.TextFrame
'定义Excel变量 Dim wb As Workbook Dim ws As Worksheet Dim lastRow As Long Dim i As Long
'打开Illustrator文件 Set aiApp = CreateObject("Illustrator.Application") Set aiDoc = aiApp.Open("C:\IllustratorTemplate.ai")
'获取Excel工作簿和工作表 Set wb = ThisWorkbook Set ws = wb.Worksheets("Sheet1")
'获取Excel表格数据行数 lastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
'循环模板文字层 For Each aiLayer In aiDoc.Layers '如果图层名称为'Text',则循环文字框 If aiLayer.Name = "Text" Then For Each aiTextItem In aiLayer.TextFrames '循环Excel A列单元格的值依次附给文字层,如果文字层循环到最后就结束循环 For i = 1 To lastRow aiTextItem.Contents = ws.Cells(i, 1).Value If i = aiLayer.TextFrames.Count Then Exit For Next aiTextItem End If Next aiLayer
'保存Illustrator文件 aiDoc.Save aiDoc.Close
'释放Illustrator对象 Set aiTextItem = Nothing Set aiLayer = Nothing Set aiDoc = Nothing Set aiApp = Nothing
原文地址: https://www.cveoy.top/t/topic/nKvY 著作权归作者所有。请勿转载和采集!