The document describes a VBA module for creating various barcode symbols, including Code 128, Data Matrix, QR, and Aztec, within Excel. It includes functions for generating these barcodes and provides options for customization, such as security levels and dimensions. The module also features functionality for updating barcodes and handling Kanji conversion strings from external files.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
1 views
Modul Barcode
The document describes a VBA module for creating various barcode symbols, including Code 128, Data Matrix, QR, and Aztec, within Excel. It includes functions for generating these barcodes and provides options for customization, such as security levels and dimensions. The module also features functionality for updating barcodes and handling Kanji conversion strings from external files.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3
Attribute VB_Name = "ModulBarcode"
' Barcode symbol creation by VBA
' Author: alois zingl ' Version: V1.1 jan 2016 ' Copyright: Free and open-source software ' http://members.chello.at/~easyfilter/barcode.html ' Description: the indention of this library is a short and compact implementation to create barcodes ' of Code 128, Data Matrix, (micro) QR or Aztec symbols so it could be easily adapted for individual requirements. ' The Barcode is drawn as shape in the cell of the Excel sheet. ' The smallest bar code symbol fitting the data is automatically selected, ' but no size optimization for mixed data types in one code is done. ' Functions: ' DataMatrix(text As String, Optional rectangle As Integer) ' QuickResponse(text As String, Optional level As String = "L", Optional version As Integer = 1) ' Aztec(text As String, Optional security As Integer, Optional layers As Integer = 1) ' Code128(text As String) ' Option Explicit
' add description to user defined barcode functions
Public Function utf16to8(text As String) As String Dim i As Integer, c As Long utf16to8 = text For i = Len(text) To 1 Step -1 c = AscW(Mid(text, i, 1)) And 65535 If c > 127 Then If c > 4095 Then utf16to8 = Left(utf16to8, i - 1) + Chr(224 + c \ 4096) + Chr(128 + (c \ 64 And 63)) + Chr(128 + (c And 63)) & Mid(utf16to8, i + 1) Else utf16to8 = Left(utf16to8, i - 1) + Chr(192 + c \ 64) + Chr(128 + (c And 63)) & Mid(utf16to8, i + 1) End If End If Next i End Function
'update all barcodes in active sheet
Public Sub updateBarcodes() Attribute updateBarcodes.VB_Description = "Updates all barcode shapes of the actual sheet." Attribute updateBarcodes.VB_ProcData.VB_Invoke_Func = "q\n14" Dim shp As Shape, bc As Variant, str As String On Error Resume Next For Each shp In ActiveSheet.Shapes ' delete all lost barcode shapes If shp.Type = msoAutoShape Then str = LCase(shp.AlternativeText) For Each bc In Array("aztec", "code128", "datamatrix", "qrcode") If Left(str, Len(bc)) = bc Then shp.Title = "" ' force redraw If InStr(LCase(Range(shp.Name).Formula), bc) = 0 Then shp.Delete Exit For End If Next bc End If Next shp Application.CalculateFull ' refresh all barcodes Kanji End Sub
' read/write kanji conversion string from/to file
Public Sub Kanji() Dim p As Variant, s As Worksheet, k1 As String, c As Long Const k = "kanji" ' property name For Each s In Application.ThisWorkbook.Worksheets For Each p In s.CustomProperties ' look for kanji conversion string If p.Name = k Then If Len(p.Value) > 10000 Then k1 = p.Value Next p Next s ChDir Application.ThisWorkbook.Path If k1 = "" Then ' not found, get from file p = Application.GetOpenFilename("Excel Files (*.xlsm), *.xlsm", 1, "Read Kanji Conversion String for QRCodes from 'barcode.xlsm'") If p <> False Then Application.ScreenUpdating = False With Workbooks.Open(p, 0, True) For Each s In .Worksheets For Each p In s.CustomProperties ' look for kanji conversion string If p.Name = k Then If Len(p.Value) > 10000 Then k1 = p.Value Next p Next s .Close End With Application.ScreenUpdating = True If Len(k1) < 10000 Or (Len(k1) And 1) Then MsgBox "No Kanji conversion string for QRCodes found in Excel file." For Each s In Application.ThisWorkbook.Worksheets c = 0 For Each p In s.CustomProperties ' look for kanji conversion string If p.Name = k Then p.Value = k1: c = 1 Next p If c = 0 Then s.CustomProperties.Add k, k1 Next s End If End If End Sub