|
楼主 |
发表于 2024-3-14 15:45
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
bartender automation 版本可以实现excel与模板的调用,
下面的代码就是automation版本的excel VBA调用btw模板的代码
Sub Test()
Dim i%, j%, FilePath$, str$, arr
Dim btApp As BarTender.Application
Dim btFormat As BarTender.Format
If Len(Dir(ThisWorkbook.Path & "\moduls_up.btw")) = 0 Then
MsgBox "本目录当中没有[moduls_up.btw]文件,请核实后重试!", vbCritical, "错误提示"
Exit Sub
End If
i = Range("A1048576").End(xlUp).Row
arr = Sheet1.Range("A1:E" & i)
Set btApp = CreateObject("BarTender.Application")
btApp.Visible = False
Set btFormat = btApp.Formats.Open(ThisWorkbook.Path & "\moduls_up.btw")
For i = 2 To UBound(arr)
btFormat.SetNamedSubStringValue "ITEM", arr(i, 2)
btFormat.SetNamedSubStringValue "ITEM_DESC", arr(i, 3)
btFormat.SetNamedSubStringValue "sn", arr(i, 5)
btFormat.PrintOut
Next
btFormat.Close btDoNotSaveChanges
btApp.Quit
End Sub
Sub Test1()
Dim i%, j%, FilePath$, str$, arr
Dim btApp As BarTender.Application
Dim btFormat As BarTender.Format
If Len(Dir(ThisWorkbook.Path & "\WO_Barcode-4X3_UP.btw")) = 0 Then
MsgBox "本目录当中没有[WO_Barcode-4X3_UP.btw]文件,请核实后重试!", vbCritical, "错误提示"
Exit Sub
End If
i = Range("A1048576").End(xlUp).Row
arr = Sheet1.Range("A1:E" & i)
Set btApp = CreateObject("BarTender.Application")
btApp.Visible = False
Set btFormat = btApp.Formats.Open(ThisWorkbook.Path & "\WO_Barcode-4X3_UP.btw")
For i = 2 To UBound(arr)
btFormat.SetNamedSubStringValue "WO_Number", arr(i, 1)
btFormat.SetNamedSubStringValue "ITEM", arr(i, 2)
btFormat.SetNamedSubStringValue "ITEM_DESC", arr(i, 3)
btFormat.SetNamedSubStringValue "SN", arr(i, 5)
btFormat.PrintOut
Next
btFormat.Close btDoNotSaveChanges
btApp.Quit
End Sub |
|