Public Function GetCode128B(ByVal rn As Range) As String
Dim result As String, STR As String
Dim checksum As Integer, i_tmp As Integer
Dim checkCode As String '生成验证码
checksum = 104
STR = rn.Value
For i = 1 To Len(STR) Step 1
i_tmp = AscW(Mid(STR, i, 1))
If i_tmp >= 32 Then
checksum = checksum + (i_tmp - 32) * i
Else
checksum = checksum + (i_tmp + 64) * i
End If
Next
checksum = checksum Mod 103
If checksum < 95 Then
checksum = checksum + 32
Else
checksum = checksum + 100
End If
checkCode = ChrW(checksum)
result = ChrW(204) + STR + checkCode + ChrW(206)
GetCode128B = result
End Function
Sub 转化()
Dim n As Integer, i As Integer
n = Selection.Count
For i = 1 To n
If Selection.Cells(i) <> '' Then
Application.EnableEvents = False
Selection.Cells(i).Font.Name = 'Code 128'
Selection.Cells(i) = GetCode128B(Selection.Cells(i))
Application.EnableEvents = True
End If
Next
End Sub
联系客服