Visual Basic VBA Barcode Macro & Functions Tutorial
|"The IDAutomation Code 128 Barcode Font and VBA Macros enabled us to integrate barcoding into a Microsoft Excel spreadsheet that works cross-platform between Classic Macintosh, OS-X and Microsoft Windows operating systems." - Charles Daneri, Objective Systems, LLC (computer consulting firm), Baltimore, MD.|
These Office Macros consist of pure VBA modules with customizable code, functions and other options that allow for dynamic and variable data barcode generation. Consequently, this also means that the implementation may be more complicated for the average user. These font encoder tools format data into a text string that will display a readable barcode when the appropriate IDAutomation font is applied to it.
The Macros are free to use with the purchase of any IDAutomation linear barcode font and are compatible with Microsoft Office 2000 and greater running on Windows« or Office 2004 and 2011 for Mac platforms. This tool is not compatible with Office 2008 for Mac because that version does not have VBA capability. IDAutomation has a variety of Mac Barcode Integration options for those using Microsoft Office 2008 for Mac. Mac users and those located outside of the US Western character set should use the IDAutomation Universal Barcode Font Advantage package with related Universal Font VBA functions for Code 128 and Interleaved 2 of 5 fonts.
The barcode Macros and functions reside inside the Excel file as a custom VBA module. To use these barcode functions in an Excel spreadsheet, the IDAutomationVBA module must be imported. If the IDAutomationVBA.bas file is not available for import, it may be exported from the sample spreadsheet provided in the downloaded file. With all 2D font packages, such as QR-Code and Data-Matrix, the .bas file will reside in the product zip file.
Note: The Visual Basic Editor feature was removed from Excel for Mac 2008, and thus this font tool cannot be used in that environment.
The VBA code, functions and Macros reside inside the access database as a VBA module. To use the functions in another Access database, the module must be copied to the other database, or the module must be exported from the sample database and imported into the other database.
Before starting, ensure that these VBA Macros will achieve the desired goal. If uncertain, consult the Excel Barcode Integration Guide for a variety of scenarios and product suggestions. After downloading the file and extracting its contents, open the sample Excel spreadsheet provided. This spreadsheet contains some examples for various barcode types. A VBA module is included in the sample spreadsheet that contains custom functions and Macros that format data to IDAutomation's barcode fonts. Use the sample spreadsheet as a reference for creating barcodes if help is needed, or contact IDAutomation for additional support.
|"I found good documentation on your product, and clearly defined license terms. Your web site is well designed and has a wealth of information. We have been able to implement barcoded data collection and reporting. The barcode font has enabled us to streamline our data collection process significantly. It was extremely simple to set up. We use the Microsoft Excel Macro to create internal forms that can easily be scanned throughout our manufacturing process." Thomas Bell, Cynosure, Westford, MA|
IDAutomation's barcode fonts and Macros provide an easy method of barcoding a column in Excel. In this example, Code 128 barcodes are created in Column B from data in Column A. This example assumes the Code 128 Barcode Font Package has been installed, and the VBA module has been imported into the spreadsheet.
After the appropriate files have been downloaded and extracted, open the sample Access database provided. This database contains one table, one module and some sample reports. The module contains custom VBA code, functions and Macros. The sample database should be used as a reference if help is needed.
=Code128([Table1.Field1])If unsure of which function to use, consider the =Code128([field]) function with Code 128 Barcode Fonts.
=Code128("PREFIX" & [Field1])or
=Code128([Field1] & [Field2])or
=Code128([Field1] & "," & [Field2])
=Code128([Field1] & "~009" & [Field2],0,True)
Note: When distributing Access Databases, the associated barcode font must be installed on each computer that prints the barcodes. If this is inconvenient, the Native Barcode Generator for Access is a complete barcode generator object that stays embedded in the database, which means no fonts need to be installed on user computers. For more information about other methods of barcoding in Access, please refer to the Microsoft Access Barcode Integration Guide.
If a large amount of data needs to be encoded, the PDF417 Barcode Font and Encoder or the Data Matrix Barcode Font and Encoder may be the best options as these 2D barcode types allow for encoding of more data.
Video Tutorial Create a Barcode in Access 2010
Before starting this barcode tutorial, ensure VBA Macros are the desired implementation for a Word mail-merge. An easier method exists when using Codabar or Code 39 fonts, and this is explained further in the Barcode Integration Guide for Microsoft Word.
Excel must be used as the data source when creating barcodes in a Microsoft Word mail merge using Macros. The field used for the data source in Word should be the column in Excel where the formula has been applied, which is used to format the data to the barcode font. It is best to use the last column of the spreadsheet in order to avoid merging conflicts.
To set up an Excel spreadsheet with these barcode Macros, refer to the Barcode Tutorial for Excel.
Note: C128 ReturnTypes 6 through 9 are not currently supported in Excel-Word mail-merges.
The functions listed below are available in IDAutomation's IDAutomationVBA.bas file and are only valid when used with the font listed in the "font to use" column. Functions beginning with IDAutomation_Uni_ may only be used with the IDAutomation Universal Barcode Font Advantage™ package and are supplied in the IDAutomationNativeWindowsDLLVBA.bas file provided within that package.
DataToEncode is the string data type for all functions listed below. Other data types such as numbers or dates may need to be converted to the string data type to be properly encoded. Additional parameters are available for some functions, and are optional. For example, Code128("123456",0,True). For UPC-A, UPC-E & EAN-13, the +2 and +5 add-on codes may be created by adding the digits to the end of the data being encoded.
|VBA Functions for Standard Barcode Fonts|
|Barcode Type||Barcode Function Methods and Notes||Required Font|
Human Readable text is enabled when ReturnType = 6
Code128("123456789012", 6, 0)
|IDAutomation recommends using
Auto Mode for most situations.
Code128a (DataToEncode, C128 ReturnType)
Code128b (DataToEncode, C128 ReturnType)
Code128c (DataToEncode, C128 ReturnType)
Code39Mod43 (DataToEncode, ReturnType)
GS1-128 is enabled in Code 128 Auto by setting ApplyTilde to True. Human Readable AIs may be created by setting the C128 ReturnType to 6. Example:
Code128("(12)3456789012", 6, 1)
|Interleaved 2 of 5||
I2of5Mod10 (DataToEncode, ReturnType)
Example: I2of5Mod10("123456789", 1)
NOTE: ReturnType 3 generates an OPC (Optical Product Code) symbol. OPC is also known as Vision Council of America OPC, VCA BarCode & VCA OPC. Example: I2of5Mod10("020748721", 3)
|MSI / Plessey||MSI (DataToEncode, ReturnType)||IDAutomationMSI|
|USPS IntelligentMail (IMb)||
Included only in the purchased version of the USPS IMb Font Package.
|USPS Postnet||Postnet (DataToEncode, ReturnType)||IDAutomationPOSTNET|
|USPS Planet||Planet (DataToEncode, ReturnType)||IDAutomationPOSTNET|
|not applicable||MOD10 (DataToEncode)||not applicable|
|not applicable||SpliceText (DataToEncode, SpacingNumber, ApplyTilde)||not applicable|
|Functions for the Universal Barcode Font|
All functions listed
below are preceded with IDAutomation_Uni_.*
They may only be used with the
IDAutomation Universal Barcode Font Advantage™ and are supplied
in the IDAutomationNativeWindowsDLLVBA.bas
file provided within that package. *
Note: Excel 2004 for Mac requires the functions to be lowercase. Ex: idautomation_uni_c128
|Barcode Type||Universal Barcode Function Methods and Notes||Required Font|
Note: Code128() is the recommended method to use. Code128() is also used to create GS1-128.
IDAutomation_Uni_C128 ("╩8100712345╩2112WH5678", TRUE)
Excel for Mac:
idautomation_uni_c128 ("╩8100712345╩2112WH5678", TRUE)
|not applicable||C128HR (DataToEncode,
Returns text for Code 128 barcodes, such as for GS1-128.
IDAutomation_Uni_C39 ("123456789", 3, TRUE )
Excel for Mac:
idautomation_uni_c39 ("123456789", 3, TRUE )
N_Dimension, StartChar, StopChar)
IDAutomation_Uni_Codabar ("123456789", 3,"A","B" )
Excel for Mac:
idautomation_uni_codabar ("123456789", 3,"A","B" )
|Interleaved 2 of 5||IDAutomation_Uni_I2of5 (DataToEncode, N_Dimension, IncludeCheckDigit)||IDAutomation_Uni|
|MSI / Plessey||IDAutomation_Uni_MSI (DataToEncode, N_Dimension, IncludeCheckDigit)||IDAutomation_Uni|
|USPS IntelligentMail||IDAutomation_Uni_IntelligentMail (DataToEncode) **||IDAutomation_Uni|
|USPS Postnet||IDAutomation_Uni_Postnet (DataToEncode, IncludeCheckDigit)||IDAutomation_Uni|
|USPS Planet||IDAutomation_Uni_Planet (DataToEncode, IncludeCheckDigit)||IDAutomation_Uni|
|Functions for the DataBar Barcode Font|
|These functions listed below are preceded with IDAutomation_DataBar and are only provided with the IDAutomation DataBar Font Advantage Package.|
|Barcode Type||DataBar Barcode Function Methods and Notes||Required Font|
|DataBar||DataBar (DataToEncode)||IDAutomation DataBar 34|
|DataBar Expanded||DataBarExpanded (DataToEncode, 22)||IDAutomation DataBar 34|
|DataBar Exp. Stacked||DataBarExpanded (DataToEncode, Segments)||IDAutomation DataBar 34|
|DataBar Limited||DataBarLimited (DataToEncode)||IDAutomation DataBar 13|
|DataBar Stacked||DataBarStacked (DataToEncode)||IDAutomation DataBar 13|
|DataBar Stacked Omnidirectional||DataBarStackedOmniDirectional (DataToEncode)||IDAutomation DataBar 34|
|DataBar Truncated||DataBar (DataToEncode)||IDAutomation DataBar 13|
|2D Font Functions|
Regarding all symbologies listed in this section below:
|Barcode Type||Function Methods | Notes||Required Font|
EncDM(DataToEncode) or EncNDM(DataToEncode)
All parameters are set to default except ApplyTilde which is set to 1 and the Encoding Mode which is set to ASCII.
|IDAutomation2D or IDAutomationDMatrix|
All parameters are set to default except ApplyTilde which is set to 1.
|PDF417||Refer to the PDF417 User Manual.||IDAutomation2D or IDAutomationPDF417|
|Aztec||Refer to the Aztec User Manual.||IDAutomation2D|
|Maxicode||Refer to the Maxicode User Manual.||IDAutomation Maxicode|
** The USPS Intelligent Mail (IMb) function is supplied in pure VBA code with the purchased version of the associated font package.
| ©Copyright 2015
IDAutomation.com, All Rights Reserved.
Barcode Fonts | Components | Scanners | Support | Contact Us
Over 70% of Fortune 100 companies use IDAutomation's products to automate their businesses.