Example of Creating Template Files with Excel VBA
Create a Template File (Label Layout File)
-
1.
The following is a description using a fixed asset list created with Excel.
- 2. Select View -> Toolbars -> Control Toolbox -> Command Button and create a command button (Caption of the button is "Print Label").
-
3.
Double-click Print Label to start the Visual Basic Editor and write the following code.
Private Sub CommandButton1_Click() 'Create a b-PAC object Dim ObjDoc As bpac.Document Set ObjDoc = CreateObject("bpac.Document") 'Open a template file created with P-touch Editor '(Put this Excel file and the template file in then same folder) ObjDoc.Open (ActiveWorkbook.Path & "¥asset.lbx") Dim str As String 'Repeat for the specified rows For r = 1 To Selection.Areas(1).Rows.Count 'Calculate the row number Dim i As Integer i = Selection.Areas(1).Cells(r, 1).Row 'Assign the content of the cell of "Fixed asset name" 'to the text object of "Fixed asset name" ObjDoc.GetObject("Name").Text = Cells(i, 3).Text 'Assign the content of the cell of "Management section" 'to the text object of "Management section" ObjDoc.GetObject("Section").Text = Cells(i, 4).Text 'Assign the content of the cell of "Identification No." 'to the text object of "Identification No." ObjDoc.GetObject("Number").Text = Cells(i, 5).Text 'Assign the content of the cell of "Identification No." 'to the barcode object. ObjDoc.GetObject("QRCode1").Text = Cells(i, 5).Text 'Print ObjDoc.StartPrint "DocumentName", bpoAutoCut ObjDoc.PrintOut 1, bpoAutoCut ObjDoc.EndPrint Next 'Free the b-PAC object ObjDoc.Close Set ObjDoc = Nothing End Sub
Note
- You can also change an image object and configure the font settings.
- For methods available from b-PAC, refer to the b-PAC SDK documentation.
- 4. After writing the code, close Visual Basic Editor. From Control Toolbox, click the Exit Design Mode button to exit Design Mode.
- 5. Save the Excel file in the same folder as the template file.
- 6. Select rows to print and click the Print Label button.
Labels are printed with values of cells of selected rows while the label layout file created with P-touch Editor is used as the template.
Download
FAQ
For Developers
-
Choose from Purposes
Label printing, printer setup and management information.
-
b-PAC
Information on application development tools for Windows
-
Mobile SDK
Information on application development tools for mobile terminals
-
Command Reference
Information on control command reference for label printers and mobile printers
-
Versatile software
Information on versatile software provided by Brother
-
Choose from Models
Introduction of Brother tools applicable to your model
-
Video Library
Videos showing how to use SDK and other information
-
Contact Us
Fill out the contact us form if you have questions about Brother developer tool.