Sub UpdateIllustratorTemplate()

'定义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
                
                '将Excel单元格的值更新到Illustrator文字框中
                aiTextItem.Contents = ws.Cells(i, 1).Value
                
                '保存Illustrator文件
                aiDoc.Save
                
            Next i
            
        Next aiTextItem
        
    End If
    
Next aiLayer

'关闭Illustrator文件
aiDoc.Close

'释放Illustrator变量
Set aiTextItem = Nothing
Set aiLayer = Nothing
Set aiDoc = Nothing
Set aiApp = Nothing

'释放Excel变量
Set ws = Nothing
Set wb = Nothing

End Su


原文地址: https://www.cveoy.top/t/topic/dHJD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录