<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.micylou.com/index.php?action=history&amp;feed=atom&amp;title=EAN128_barcodes_in_Excel</id>
	<title>EAN128 barcodes in Excel - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.micylou.com/index.php?action=history&amp;feed=atom&amp;title=EAN128_barcodes_in_Excel"/>
	<link rel="alternate" type="text/html" href="https://wiki.micylou.com/index.php?title=EAN128_barcodes_in_Excel&amp;action=history"/>
	<updated>2026-04-06T13:14:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.micylou.com/index.php?title=EAN128_barcodes_in_Excel&amp;diff=1201&amp;oldid=prev</id>
		<title>DochyJP: Page creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.micylou.com/index.php?title=EAN128_barcodes_in_Excel&amp;diff=1201&amp;oldid=prev"/>
		<updated>2021-11-24T11:53:12Z</updated>

		<summary type="html">&lt;p&gt;Page creation&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;!-- Template Infobox Generic--&amp;gt;&lt;br /&gt;
{{Template:Class-Infobox-Generic&amp;lt;!-- ALL MUST BE FILLED IN --&amp;gt;&lt;br /&gt;
	|image = &amp;lt;!-- If an logo is required, enter the link here --&amp;gt;&lt;br /&gt;
	|Section = [[Section::{{PAGENAME}}]]&lt;br /&gt;
	|Source = [[Source::DataSource]]  &amp;lt;!-- [[Source::DataSource]], [[Source::Query]], ... --&amp;gt;&lt;br /&gt;
	|Language = [[Language::English]] &amp;lt;!-- [[Language::English]], [[Language::Français]], [[Language::Nederlands]] --&amp;gt;&lt;br /&gt;
	|Topic =  [[Topic ::Microsoft]] &amp;lt;!-- [[Topic ::Mediawiki]], [[Topic ::Microsoft]], ... --&amp;gt;&lt;br /&gt;
	|SubTopic = [[SubTopic::Excel]] &amp;lt;!-- [[SubTopic::Mediawiki Extension]], [[SubTopic::Office 365]] , [[Subtopic::Quiz]] ... --&amp;gt;&lt;br /&gt;
        |DocumentType =  [[DocumentType::Documentation]] &amp;lt;!-- [[DocumentType::User Guide]], [[DocumentType::Procedure]], [[DocumentType::Script]], [[DocumentType::Gallery]], [[DocumentType::Training]]...--&amp;gt;&lt;br /&gt;
	|LastEditBy = [[LastEditBy::{{REVISIONUSER}}]] &lt;br /&gt;
	|LastEdit = [[LastEdit::{{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}]] &lt;br /&gt;
	|Status = [[Status::Active]] &amp;lt;!--[[Status::Active]]  [[Status::Development]] [[Status::Obsolete]] [[Status::Archived]] [[Status::To Delete]]--&amp;gt;&lt;br /&gt;
	|Access = [[Access::free]] &amp;lt;!--[[Access::free]] [[Access::Private]] [[Access::Subscription]] --&amp;gt;&lt;br /&gt;
	&amp;lt;!-- Template version 1.01 --&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;!-- End of Template Infobox Generic--&amp;gt;&lt;br /&gt;
== Easily generate Code 128 barcodes in Excel ==&lt;br /&gt;
A Code 128 barcode has six sections:&lt;br /&gt;
#Quiet zone&lt;br /&gt;
#Start character&lt;br /&gt;
#Encoded data&lt;br /&gt;
#Check character&lt;br /&gt;
#Stop character&lt;br /&gt;
#Quiet zone&lt;br /&gt;
&lt;br /&gt;
The check character is calculated from a weighted sum (modulo 103) of all the characters. Because of this, the generation of Code 128 barcodes is not as simple as typing the number sequence into a programme using a barcode font. Attempting to do this with Code 128 barcodes will fail.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Download the [http://www.dafont.com/code-128.font Code 128 barcode font] and install in your fonts folder at c:\windows\fonts. (You will need administrator permissions to do this). Without being administrator, you can just drag &amp;amp; drop the ttf file from Font management under Windows.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Ensure that you have the Developer module enabled in Excel.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Create a new Microsoft Excel sheet. Create a table (making sure that you ‘format as table‘) with the following structure and headings:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! Barcode !! Barcode String !! Barcode Presentation !! Check&lt;br /&gt;
|-&lt;br /&gt;
| X ||  X ||  X ||  X &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
In Excel, go to the Developer ribbon and choose “Visual Basic”.&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Right-click on “Modules” in the tree on the left and select “Insert Module”. Then paste the following code :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Option Explicit&lt;br /&gt;
Public Function Code128(SourceString As String)&lt;br /&gt;
    'Written by Philip Treacy, Feb 2014&lt;br /&gt;
    'http://www.myonlinetraininghub.com/create-barcodes-with-excel-vba&lt;br /&gt;
    'This code is not guaranteed to be error free.  No warranty is implied or expressed. Use at your own risk and carry out your own testing&lt;br /&gt;
    'This function is governed by the GNU Lesser General Public License (GNU LGPL) Ver 3&lt;br /&gt;
    'Input Parameters : A string&lt;br /&gt;
    'Return : 1. An encoded string which produces a bar code when dispayed using the CODE128.TTF font&lt;br /&gt;
    '         2. An empty string if the input parameter contains invalid characters&lt;br /&gt;
    Dim Counter As Integer&lt;br /&gt;
    Dim CheckSum As Long&lt;br /&gt;
    Dim mini As Integer&lt;br /&gt;
    Dim dummy As Integer&lt;br /&gt;
    Dim UseTableB As Boolean&lt;br /&gt;
    Dim Code128_Barcode As String&lt;br /&gt;
    If Len(SourceString) &amp;gt; 0 Then&lt;br /&gt;
        'Check for valid characters&lt;br /&gt;
        For Counter = 1 To Len(SourceString)&lt;br /&gt;
            Select Case Asc(Mid(SourceString, Counter, 1))&lt;br /&gt;
                Case 32 To 126, 203&lt;br /&gt;
                Case Else&lt;br /&gt;
                    MsgBox &amp;quot;Invalid character in barcode string.&amp;quot; &amp;amp; vbCrLf &amp;amp; vbCrLf &amp;amp; &amp;quot;Please only use standard ASCII characters&amp;quot;, vbCritical&lt;br /&gt;
                    Code128 = &amp;quot;&amp;quot;&lt;br /&gt;
                    Exit Function&lt;br /&gt;
            End Select&lt;br /&gt;
        Next&lt;br /&gt;
        Code128_Barcode = &amp;quot;&amp;quot;&lt;br /&gt;
        UseTableB = True&lt;br /&gt;
        Counter = 1&lt;br /&gt;
        Do While Counter &amp;lt;= Len(SourceString)&lt;br /&gt;
            If UseTableB Then&lt;br /&gt;
                'Check if we can switch to Table C&lt;br /&gt;
                mini = IIf(Counter = 1 Or Counter + 3 = Len(SourceString), 4, 6)&lt;br /&gt;
                GoSub testnum&lt;br /&gt;
                If mini% &amp;lt; 0 Then 'Use Table C&lt;br /&gt;
                    If Counter = 1 Then&lt;br /&gt;
                        Code128_Barcode = Chr(205)&lt;br /&gt;
                    Else 'Switch to table C&lt;br /&gt;
                        Code128_Barcode = Code128_Barcode &amp;amp; Chr(199)&lt;br /&gt;
                    End If&lt;br /&gt;
                    UseTableB = False&lt;br /&gt;
                Else&lt;br /&gt;
                    If Counter = 1 Then Code128_Barcode = Chr(204) 'Starting with table B&lt;br /&gt;
                End If&lt;br /&gt;
            End If&lt;br /&gt;
            If Not UseTableB Then&lt;br /&gt;
                'We are using Table C, try to process 2 digits&lt;br /&gt;
                mini% = 2&lt;br /&gt;
                GoSub testnum&lt;br /&gt;
                If mini% &amp;lt; 0 Then 'OK for 2 digits, process it&lt;br /&gt;
                    dummy% = Val(Mid(SourceString, Counter, 2))&lt;br /&gt;
                    dummy% = IIf(dummy% &amp;lt; 95, dummy% + 32, dummy% + 100)&lt;br /&gt;
                    Code128_Barcode = Code128_Barcode &amp;amp; Chr(dummy%)&lt;br /&gt;
                    Counter = Counter + 2&lt;br /&gt;
                Else 'We haven't got 2 digits, switch to Table B&lt;br /&gt;
                    Code128_Barcode = Code128_Barcode &amp;amp; Chr(200)&lt;br /&gt;
                    UseTableB = True&lt;br /&gt;
                End If&lt;br /&gt;
            End If&lt;br /&gt;
            If UseTableB Then&lt;br /&gt;
                'Process 1 digit with table B&lt;br /&gt;
                Code128_Barcode = Code128_Barcode &amp;amp; Mid(SourceString, Counter, 1)&lt;br /&gt;
                Counter = Counter + 1&lt;br /&gt;
            End If&lt;br /&gt;
        Loop&lt;br /&gt;
        'Calculation of the checksum&lt;br /&gt;
        For Counter = 1 To Len(Code128_Barcode)&lt;br /&gt;
            dummy% = Asc(Mid(Code128_Barcode, Counter, 1))&lt;br /&gt;
            dummy% = IIf(dummy% &amp;lt; 127, dummy% - 32, dummy% - 100)&lt;br /&gt;
            If Counter = 1 Then CheckSum&amp;amp; = dummy%&lt;br /&gt;
            CheckSum&amp;amp; = (CheckSum&amp;amp; + (Counter - 1) * dummy%) Mod 103&lt;br /&gt;
        Next&lt;br /&gt;
        'Calculation of the checksum ASCII code&lt;br /&gt;
        CheckSum&amp;amp; = IIf(CheckSum&amp;amp; &amp;lt; 95, CheckSum&amp;amp; + 32, CheckSum&amp;amp; + 100)&lt;br /&gt;
        'Add the checksum and the STOP&lt;br /&gt;
        Code128_Barcode = Code128_Barcode &amp;amp; Chr(CheckSum&amp;amp;) &amp;amp; Chr$(206)&lt;br /&gt;
    End If&lt;br /&gt;
    Code128 = Code128_Barcode&lt;br /&gt;
    Exit Function&lt;br /&gt;
testnum:&lt;br /&gt;
        'if the mini% characters from Counter are numeric, then mini%=0&lt;br /&gt;
        mini% = mini% - 1&lt;br /&gt;
        If Counter + mini% &amp;lt;= Len(SourceString) Then&lt;br /&gt;
            Do While mini% &amp;gt;= 0&lt;br /&gt;
                If Asc(Mid(SourceString, Counter + mini%, 1)) &amp;lt; 48 Or Asc(Mid(SourceString, Counter + mini%, 1)) &amp;gt; 57 Then Exit Do&lt;br /&gt;
                mini% = mini% - 1&lt;br /&gt;
            Loop&lt;br /&gt;
        End If&lt;br /&gt;
        Return&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Go back to your Excel sheet and insert the following formulae:&lt;br /&gt;
&lt;br /&gt;
*In cell B2 (“Barcode String”), insert =Code128([@Barcode])&lt;br /&gt;
*In cell C2 (“Barcode Presentation”), insert =[@[Barcode String]]&lt;br /&gt;
*In cell D2 (“Check”), insert: =IF(ISNUMBER(SEARCH(&amp;quot;Â&amp;quot;,[@[Barcode Presentation]],1)),&amp;quot;Error!&amp;quot;,&amp;quot;&amp;quot;)&lt;br /&gt;
The formulae should copy down the entire columns. Save your sheet. Attention, this require an xlsm file format.&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
Highlight Column C and change the font to “Code 128”. Now when you enter data into cell A2, a barcode should be displayed in cell C2 and so-on down the entire sheet.&lt;br /&gt;
&lt;br /&gt;
If this doesn’t work, you may need to close and re-open Excel at this stage.&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>DochyJP</name></author>
	</entry>
</feed>