FAQ TBarCode OCX
How to Add a Barcode Control Programmatically in Word VBA?
How to Add a Barcode Control Programmatically in Word VBA?
Sample code:
Dim barcodeShape As InlineShape
' switch to design mode (optional)
' ActiveDocument.ToggleFormsDesign
' Insert barcode object at actual position in document
Set barcodeShape = Selection.InlineShapes.AddOLEControl(ClassType:="TBarCode10.TBarCode10.1")
' change size
barcodeShape.Width = 200
barcodeShape.Height = 100
' adjust barcode properties programmatically
barcodeShape.OLEFormat.Object.Barcode = 20 ' 20 = Code-128
barcodeShape.OLEFormat.Object.Text = "Hello"
The “AddOLEControl“ function accepts a second parameter which can be a Range object where to place the Barcode Control.