我最近购买了Brother QL-570标签打印机,不幸的是,当我尝试使用Brother提供的VBA样品时,它无法运行:
Option Explicit
Const sPath = "C:\Temp\Asset2.lbx"
Private Sub cmdPrint_Click()
Dim bRet As Boolean
Dim ObjDoc As bpac.Document
Set ObjDoc = CreateObject("bpac.Document")
'Open lbx file
bRet = ObjDoc.Open(sPath)
If (bRet <> False) Then
' Determine how many rows the user selected
Dim iTotal As Integer
iTotal = Selection.Rows.Count
' Start Print
ObjDoc.StartPrint "", bpoDefault
Dim r As Integer
For r = 1 To iTotal
Dim Str As String
Dim iRow As Integer
'Data Text (Document)
iRow = Selection.Cells(r, 1).Row
Str = Cells(iRow, 1).Text
ObjDoc.GetObject("objDocument").Text = Str
'Data Text(Barcode)
ObjDoc.GetObject("objBarcode").Text = Str
'Data Text (Period)
Str = Cells(iRow, 2).Text
ObjDoc.GetObject("objPeriod").Text = Str
'Data Text (Management)
Str = Cells(iRow, 3).Text
ObjDoc.GetObject("objManagement").Text = Str
' Print
ObjDoc.PrintOut 1, bpoDefault
Next
' End Print
ObjDoc.EndPrint
' Close object
ObjDoc.Close
End If
End Sub
我已确保在Excel VBA中包含b-Pac参考库。我也逐步完成了代码,没有出现错误。关于如何让它发挥作用的任何建议?