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 Sub

VBA 循环更新 Illustrator 模板文字层内容

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

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