vba - 使用 Microsoft Word 生成 Code 128 条码
问题描述
我正在尝试使用 Micorosft Word 2013 或 2019 和 VBA 使用以下函数生成 Code 128 条形码:
Public Function GenerateCode128B(SourceStruing As String)
Dim checkDigitValue As Integer
Dim barcodeString As String
Dim startSign As String
Dim endSign As String
Dim index As Integer
Dim c As Integer
checkDigitValue = 104
startSign = Chr(204)
endSign = Chr(206)
index = 1
barcodeString = startSign
For c = 1 To Len(SourceString) Step 1
Dim currentSign As String
currentSign = Asc(Mid(SourceString, c, 1))
If Asc(currentSign) < 32 Or Asc(currentSign) > 126 Then
GenerateCode128B = Empty
Else
barcodeString = barcodeString & Mid(SourceString, c, 1)
checkDigitValue = checkDigitValue + (Asc(currentSign) - 32) * index
index = index + 1
End If
Next
checkDigitValue = checkDigitValue Mod 103
If checkDigitValue > 94 Then
checkDigitValue = checkDigitValue + 100
Else
checkDigitValue = checkDigitValue + 32
End If
barcodeString = barcodeString & Chr(checkDigitValue) & endSign
GenerateCode128B = barcodeString
End Function
因此,我使用这种字体:https://www.dafont.com/de/code-128.font。
为了在 word 文档中显示条形码,我使用了这两条相似的行:
Selection.Font.Name = "Code 128"
Selection.TypeTest GenerateCode128B("ABC12DEF456G")
我目前的问题:如果我没有在 Windows 10 下安装字体,条形码是正确的。如果我安装字体,条形码不可读。
示例:纯文本:ABC12DEF456F
不使用特定字体的条码:ÌABC12DEF456FNÎ(正确且可读)
使用 code128.ttf 字体的条码:ƎΒΧΓƎΑΓ12ΔΕZ456ΔƎΒΓΧƎ(不正确,不可读!)
条形码显示希腊字母符号的原因可能是什么?