代表者の戯言

making barcode forVBA



I want to keep a memo on how to create barcodes in Excel VBA.


For example, let's assume that the cell B1 in Excel contains a JAN code written in numeric format.


To generate a barcode from this, follow the steps below.


Please download IDAutomationHC39M Free Version.



varcode picture

Sub Oval2_Click()


Dim inputValue As String


' Retrieve the range to be converted to barcode. In this case, it gets the value of cell B1.


inputValue = Range("B1").Value


' Format the value for the barcode (for Code39, enclose it in asterisks).


Dim barcodeValue As String


barcodeValue = "*" & inputValue & "*"


' Display the result in cell C2.


Range("C2").Value = barcodeValue


' Set the font of cell C2 to the barcode font.


Range("C2").Font.Name = "IDAutomationHC39M Free Version"


' Change to the name of the installed font.


End Sub