CODE 128 VBA

Public Function copyformat()
'copy the format of a1:a6
Sheets("sheet2").Activate
Range("a1:e6").Select
Dim v As Integer
For I = 1 To 499
v = I * 6 + 1
Range("a1:e6").Copy Cells(v, 1)

'insert the hpagebreaker
Cells(v, 1).Activate
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell

'insert formula to cells
''''Range(Cells(v + 2, 3), Cells(v + 5, 5)).ClearContents
Cells((v + 3), 2).Formula = "=sheet1!$D" & (I + 2)
'''Cells((v + 3), 3).Formula = "=sheet1!$d" & (i + 2)
Cells((v + 5), 2).Formula = "=sheet1!$c" & (I + 2)
'''Cells((v + 5), 3).Formula = "=sheet1!$c" & (i + 2)
Next
Cells(4, 2).Formula = "=sheet1!$D2"
Cells(6, 2).Formula = "=sheet1!$C2"
End Function

Public Function StringToCode128()
Dim PrintableString, CurrentValue, CurrentCharNum, CheckDigitValue, DataToEncode, WeightedTotal
Dim StringLength

For k = 1 To 500
Sheets("sheet1").Activate
DataToEncode = RTrim(LTrim(Cells(k + 1, 4)))

'Set check_total to the value of the start character
PrintableString = ""
  WeightedTotal = 104
  PrintableString = ChrW(204)
  StringLength = Len(DataToEncode)
'calculate the total of the datatoencode
  For I = 1 To StringLength
   
          CurrentCharNum = AscW(Mid(DataToEncode, I, 1))
          If CurrentCharNum < 135 Then CurrentValue = CurrentCharNum - 32
          If CurrentCharNum > 134 Then CurrentValue = CurrentCharNum - 100
          CurrentValue = CurrentValue * I
          WeightedTotal = WeightedTotal + CurrentValue
          If CurrentCharNum = 32 Then CurrentCharNum = 194
          PrintableString = PrintableString & ChrW(CurrentCharNum)
  Next
'calc the checkdigit of the datatoencode
  CheckDigitValue = (WeightedTotal Mod 103)
  If CheckDigitValue < 95 Then C128CheckDigit = ChrW(CheckDigitValue + 32)
  If CheckDigitValue > 94 Then C128CheckDigit = ChrW(CheckDigitValue + 100)
  PrintableString = PrintableString + C128CheckDigit + ChrW(206)

Sheets("sheet2").Activate
Cells(k * 6 - 3, 1) = PrintableString
Next k

For k = 1 To 500
Sheets("sheet1").Activate
DataToEncode = RTrim(LTrim(Cells(k + 1, 3)))
'code 128 character set B
PrintableString = ""
  WeightedTotal = 104
  PrintableString = ChrW(204)
  StringLength = Len(DataToEncode)
   
  For I = 1 To StringLength
   
          CurrentCharNum = AscW(Mid(DataToEncode, I, 1))
          If CurrentCharNum < 135 Then CurrentValue = CurrentCharNum - 32
          If CurrentCharNum > 134 Then CurrentValue = CurrentCharNum - 100
          CurrentValue = CurrentValue * I
          WeightedTotal = WeightedTotal + CurrentValue
          If CurrentCharNum = 32 Then CurrentCharNum = 194
          PrintableString = PrintableString & ChrW(CurrentCharNum)
  Next
   
  CheckDigitValue = (WeightedTotal Mod 103)
   
  If CheckDigitValue < 95 Then C128CheckDigit = ChrW(CheckDigitValue + 32)
  If CheckDigitValue > 94 Then C128CheckDigit = ChrW(CheckDigitValue + 100)
  PrintableString = PrintableString + C128CheckDigit + ChrW(206)

Sheets("sheet2").Activate
Cells(k * 6 - 1, 1) = PrintableString
Next k

End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值