Using barcodes in MS Office Automation |
How to create a Word document and insert a barcode into it? How to insert a barcode into MS Excel sheet? Is there any way to use a Barcode ActiveX in Word with a mail merge field and how would this be done? |
How to create a Word document and insert a barcode into it? |
Below you can see an example written in VB Script that starts the Word application and inserts a barcode into the document.
set app = CreateObject("Word.Application")You can copy this text to Notepad and save it with the .vbs extension and then start this .vbs file. This will create the file test.doc on disk "C" with a barcode in it. Besides, you can use it from VBA (Visual Basic for Applications), i.e. from Excel, Word, Access, etc. |
How to insert a barcode into MS Excel sheet? |
Below you can see an example written in VBA (Visual Basic for Applications).
Public Sub MyScript()
'create barcode object If ActiveSheet.OLEObjects.Count = 0 Then Set oleObj = ActiveSheet.OLEObjects.Add(ClassType:="ABarCode.ActiveBC.1", _ Left:=10, _ Top:=10, _ Width:=190, _ Height:=70) Else Set oleObj = ActiveSheet.OLEObjects(1) End If barcodecell = Sheets(1).Range("B2").Value Set oBarCode = oleObj.Object oBarCode.BarType = 13 'UPCA 'oBarCode.BarText = "123456789012" 'oBarCode.BarText = barcodecell oBarCode.TextAlign = 4 oleObj.LinkedCell = "$B$5" Set f = CreateObject("StdFont") f.Name = "Courier" f.Size = 25 oBarCode.Font = f End Sub |
Is there any way to use a Barcode ActiveX in Word with a mail merge field and how would this be done? |
You can use our Barcode ActiveX in a mail-merge document. You should use macros for that.
Const DataFieldIndex = 4
Here is you can download the source files.
Download First, you should create a data source that will be used for mail merge. We use an Access database in our example, but it can be any other data source (refer to MS Word documentation). Start MS Word and show the Mail Merge toolbox. Open Data Source. Insert Merge Fields. Type a "barcode marker". The phrase "BarcodePlace" is a barcode marker. The macro that will be created later will insert a barcode instead of this phrase. Change Security Level to Low or set Trusted Sources and start Visual Basic Editor (Alt+F11). Add "Barcode Type Library" to the project references. Copy and paste the text of the macro. Save the created Word document and close it. Then open it again. You can print the mail-merge document or save it to another Word document. |