如何为Excel生成Code 128条码字体(简单步骤)。

  • Share This
Hugh West

在这篇文章中,我们将学习如何生成 用于Excel的Code 128条形码字体 有一些方法可以在Excel中使用Code 128条形码字体,但大多数方法在应用上具有挑战性,而且不能在所有版本的Excel中使用。 今天,我们将演示一种在Excel中用简单的步骤生成Code 128条形码字体的方法。 在阅读完这篇文章后,你将能够非常容易地使用Code 128条形码字体。 所以,不要拖延,现在让我们开始讨论。

下载练习册

你可以从这里下载练习册。

Code 128 Barcode Font.xlsm

什么是Code 128条码字体?

代码128 是一种现代的和著名的条形码字体。 它的受欢迎程度与日俱增,因为它是一种支持字母数字字符的高密度条形码字体。

一般来说,代码128由七个部分组成。 它们是:。

  • 安静区
  • 启动符号
  • 编码数据
  • 检查符号
  • 停止符号
  • 决赛吧
  • 安静区

ǞǞǞ 代码128 条形码字体有 3 下面将简要介绍这些子集。

  • 代码128A :它支持 ASCII 没有小写字母。
  • 代码128B :它支持 ASCII 不含最初的特殊字符。
  • 代码128C : 这个子集支持 数值 .

在Excel中生成Code 128条码字体的分步程序

为了解释步骤,我们将使用一个数据集,该数据集包含了关于一些 产品 和他们的 数据 使用该方法,我们将尝试生成具有以下特征的条形码 代码128 每个产品的数据的字体。

第1步:下载Code 128字体

  • 首先,你需要下载 代码128 你可以 从这个链接下载字体 .
  • 在这之后。 提取 下载的文件夹到 C:\Windows\Fonts 文件夹。
  • 否则,解压下载的文件夹,复制 代码128 字体,并将其粘贴到 C:\Windows\Fonts 文件夹。
  • 同时,选择 继续 如果出现管理员权限窗口。

第2步:应用VBA代码

  • 第二,去 开发商 在功能区中的标签,选择 视觉基础 .
  • 因此,它将打开 视觉基础 窗口。

  • 之后,选择 插入 然后 模块 视觉基础 窗口。
  • 在这一时刻, 模块 窗口将出现。

  • 现在,我们需要输入一个代码在 模块 窗口。
  • 你可以从下面复制它并粘贴到 模块 窗口。
 Option Explicit Public Function Code128(SourceString As String) Dim Counter As Integer Dim CheckSum As Long Dim mini As Integer Dim dummy As Integer Dim UseTableB As Boolean Dim Code128_Barcode As String If Len(SourceString)> 0 Then For Counter = 1 To Len(SourceString) Select Case Asc(Mid(SourceString, Counter, 1) ) Case 32 To 126,203 Case Else MsgBox "Invalid character in barcode string" & vbCrLf & vbCrLf & "Please only use standard ASCII characters", vbCritical Code128 = " " Exit Function End Select Next Code128_Barcode = " " UseTableB = True Counter = 1 Do While Counter <=Len(SourceString) If UseTableB Then mini = IIf(Counter = 1 Or Counter + 3 = Len(SourceString), 4, 6) GoSub testnum If mini% <0 Then If Counter = 1 Then Code128_Barcode = Chr(205) Else Code128_Barcode = Code128_Barcode & Chr(199)End If UseTableB = False Else If Counter = 1 Then Code128_Barcode = Chr(204) End If End If Not UseTableB Then mini% = 2 GoSub testnum If mini% <0 Then dummy% = Val(Mid(SourceString, Counter, 2) ) dummy% =IIf(dummy% <95, dummy% + 32, dummy% + 100) Code128_Barcode = Code128_Barcode & Chr(dummy%) Counter = Counter + 2 Else Code128_Barcode = Code128_Barcode & Chr(200) UseTableB = True End If End If UseTableB Then Code128_Barcode =Code128_Barcode & Mid(SourceString, Counter, 1) Counter = Counter + 1 End If Loop For Counter = 1 To Len(Code128_Barcode) dummy% = Asc(Mid(Code128_Barcode, Counter, 1)) dummy% = IIf(dummy% <127, dummy% - 32, dummy% - 100) If Counter = 1 Then CheckSum& = dummy% CheckSum& = (CheckSum& +)(Counter - 1) * dummy%) Mod 103 Next CheckSum& = IIf(CheckSum& <95, CheckSum& + 32, CheckSum& + 100) Code128_Barcode = Code128_Barcode & Chr(CheckSum&) & Chr$(206) End If Code128 = Code128_Barcode Exit Function testnum: mini% = mini% - 1 If Counter + mini% = 0 If Asc(Mid(SourceString, Counter +mini%, 1)) 57 然后退出 Do mini% = mini% - 1 循环 End If 返回 End Function 

VBA代码解释。

在这段代码中,我们将创建一个将字符串转换为条形码的函数。 这里,我们将使用 代码128 字体。

  • 输入参数是一个字符串。
  • 在输出中,我们将得到一个条形码,在 代码128 字体,如果该字符串有效。
  • 否则,它将显示一个空字符串。
 公共函数Code128(SourceString As String) 

这一部分表示函数名称,它是 代码128() 你需要在圆括号内插入该字符串。

 Dim Counter As Integer Dim CheckSum As Long Dim mini As Integer Dim dummy As Integer Dim UseTableB As Boolean Dim Code128_Barcode As String 

这些是将在代码中使用的变量。

 If Len(SourceString)> 0 Then For Counter = 1 To Len(SourceString) Select Case Asc(Mid(SourceString, Counter, 1)) Case 32 To 126, 203 Case Else MsgBox "Invalid character in barcode string" & vbCrLf & vbCrLf & "Please only use standard ASCII characters", vbCritical Code128 = "" Exit Function End Select Next 

在这一部分,代码将检查有效的字符。 如果它发现没有有效的字符,那么,它将要求用户使用标准的 ASCII 角色。

 For Counter = 1 To Len(Code128_Barcode) dummy% = Asc(Mid(Code128_Barcode, Counter, 1)) dummy% = IIf(dummy% <127, dummy% - 32, dummy% - 100) If Counter = 1 Then CheckSum& = dummy% CheckSum& = (CheckSum& + (Counter - 1) * dummy%) Mod 103 Next 

这里,这部分计算的是 检查和 变量。

 CheckSum& = IIf(CheckSum& <95, CheckSum& + 32, CheckSum& + 100) Code128_Barcode = Code128_Barcode & Chr(CheckSum&) & Chr$(206) End If 

在这一部分,代码计算了 CheckSum ASCII 代码。 在添加了 ASCII 代码,它就会转到下一个部分。

 mini% = mini% - 1 如果Counter + mini% = 0 如果Asc(Mid(SourceString, Counter + mini%, 1)) 57 那么退出 Do mini% = mini% - 1 循环 End If 

在最后一部分,代码将检查给定字符串中的数字值。

VBA 代码是由 myonlinetraininghub.com .

  • 输入代码后,按 键盘 + S 来拯救它。
  • 在接下来的步骤中,关闭 视觉基础 窗口。

第3步:使用Code 128功能

  • 第三,我们需要使用我们通过应用以下方法创建的函数 VBA .
  • 为了做到这一点,选择 细胞D5 并输入下面的公式。
=Code128(C5)

在这里,该函数将转换以下的数据 细胞C5 变成一个条形码。

  • 在接下来的步骤中,按 进入 来看结果。

第4步:改变字体主题和大小

  • 在第四步,你需要改变字体主题和大小。
  • 为此,请选择 细胞C5 .
  • 然后,去到 首页 选项卡,并选择 代码128 在字体主题框中。
  • 同时,选择 36 在字体大小框中。

第5步:调整列宽和行高的大小

  • 在改变字体主题和大小之后,我们需要调整列宽和行高的大小。
  • 在我们的例子中,我们已经设置了宽度为 D栏 30 行高 50 .

第6步:使用填充手柄来复制公式

  • 在接下来的步骤中,选择 细胞D5 并拖动 填充手柄 下至其他细胞。

最终产出

  • 最后,改变 行高 第6行 , 7 , 8 ,以及 9 50 .
  • 完成所有步骤后,你将看到如下图所示的结果。

阅读更多:如何使用Code 39 Barcode Font for Excel (with Easy Steps)

总结

在这篇文章中,我们已经演示了一步步的程序,以生成 Code 128 Barcode Font for Excel 我希望这篇文章能帮助你 创建条形码 此外,你还可以使用工作手册进行练习。 为了做到这一点,请下载工作手册。 我们已经在文章的开头添加了工作手册。 此外,你可以访问 ǞǞǞǞ 最后,如果你有任何建议或疑问,请随时在下面的评论区提问。

Hugh West is a highly experienced Excel trainer and analyst with over 10 years of experience in the industry. He holds a Bachelor's degree in Accounting and Finance and a Master's degree in Business Administration. Hugh has a passion for teaching and has developed a unique teaching approach that is easy to follow and understand. His expert knowledge of Excel has helped thousands of students and professionals worldwide improve their skills and excel in their careers. Through his blog, Hugh shares his knowledge with the world, offering free Excel tutorials and online training to help individuals and businesses reach their full potential.