Using and automating barcodes with VBA in Word
You can use VisualBasic for Applications (VBA) to solve many things in Word. Here we will show you how to embed, use and delete the ActiveBarcode control with VBA:
Embedding the ActiveBarcode Control into a document:
In this example a barcode control will be placed at the cursors position. Then you can modify the object using the variable ab:
Dim ab As Object Set ab = Selection.InlineShapes.AddOLEObject(ClassType:="ACTIVEBARCODE.BarcodeCtrl.1", FileName:="", LinkToFile:=False, DisplayAsIcon:=False)Set the standard properties (height, width) of the object using the variable ab:
ab.Width = 200 ab.Height = 120You can access the properties and methods of the barcode object by using the property OLEFormat.Object:
ab.OLEFormat.Object.Type = 6 ab.OLEFormat.Object.Text = "987698769812"You also can use a more cleaner way to access the properties by creating and using a variable, e.g. named abObject:
Dim abObject As Object With ab.OLEFormat .Activate Set abObject = .Object End With abObject.Type = 6 abObject.Text = "987698769812"Using the following call you can cast the barcode object in an InlineShape. Note, that you can not change the barcode after the conversion.
ab.ConvertToShapeIf you do not need the control anymore you can delete it from the document:
ab.DeleteHint: If it's necessary that Windows process upcoming events (often named as "KeepWindowsAlive") within a macro, you can force this by using the following VBA function:
DoEventsThis can be necessary, e.g. if the Control must draw itself new.