コメント対応用記事(数日で削除します)

Function IndexNumber(Target1, Target2)
Dim i As Integer
For i = 0 To UBound(Target1)
If Target1(i) = Target2 Then Exit For
Next
IndexNumber = i
End Function
Sub CODE128_B()
Application.ScreenUpdating = False
Dim textcode, mynumber As Variant
Dim mycode As String
Dim c As Range
Dim i, a, q, x, y, m As Integer
Dim t As Double
Dim shbar, sh As Worksheet
textcode = Array(212222, 222122, 222221, 121223, 121322, 131222, 122213, 122312, 132212, _
221213, 221312, 231212, 112232, 122132, 122231, 113222, 123122, 123221, _
223211, 221132, 221231, 213212, 223112, 312131, 311222, 321122, 321221, _
312212, 322112, 322211, 212123, 212321, 232121, 111323, 131123, 131321, _
112313, 132113, 132311, 211313, 231113, 231311, 112133, 112331, 132131, _
113123, 113321, 133121, 313121, 211331, 231131, 213113, 213311, 213131, _
311123, 311321, 331121, 312113, 312311, 332111, 314111, 221411, 431111, _
111224, 111422, 121124, 121421, 141122, 141221, 112214, 112412, 122114, _
122411, 142112, 142211, 241211, 221114, 413111, 241112, 134111, 111242, _
121142, 121241, 114212, 124112, 124211, 411212, 421112, 421211, 212141, _
214121, 412121, 111143, 111341, 131141, 114113, 114311, 411113, 411311, _
113141, 114131, 311141, 411131)
mynumber = Array(" ", "!", """", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1" _
, "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "@", "A", "B", "C", _
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", _
"W", "X", "Y", "Z", "[", "\", "]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", _
"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", _
"}", "~", "DEL", "FNC 3", "FNC 2", "SHIFT", "CODE C", "FNC 4", "CODE A", "FNC 1")
Set sh = ActiveSheet
If IMEStatus <> vbIMEModeOff Then
SendKeys "{kanji}"
End If
x = InputBox("何列右に貼り付けますか?")
Worksheets.Add
ActiveSheet.Name = "mysh"
Set shbar = Worksheets("mysh")
Cells.Interior.Color = 16777215
Cells.ColumnWidth = 0.08
Rows("2:2").RowHeight = 15
Rows("3:3").RowHeight = 8
Cells.Font.Size = 6
sh.Activate
For Each c In Selection
mycode = "9211214"
For i = 1 To Len(c)
mycode = mycode & textcode(IndexNumber(mynumber, StrConv(Mid(c, i, 1), vbNarrow)))
Next
t = 104
For a = 1 To Len(c)
t = t + a * IndexNumber(mynumber, StrConv(Mid(c, a, 1), vbNarrow))
Next
mycode = mycode & textcode(t Mod 103)
mycode = mycode & "23311129"
shbar.Activate
m = 1
For q = 1 To Len(mycode)
Select Case q Mod 2
Case 1
For y = 1 To CInt(Mid(mycode, q, 1))
m = m + 1
Next
Case 0
For y = 1 To CInt(Mid(mycode, q, 1))
Cells(2, m).Interior.Color = 0
m = m + 1
Next
End Select
Next
With Range(Cells(3, 1), Cells(3, m))
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ShrinkToFit = True
End With
Range("A3").NumberFormatLocal = "0_ "
Range("A3").Value = c.Value
shbar.Range(Cells(2, 1), Cells(3, m)).CopyPicture Appearance:=xlScreen, Format:=xlPicture
sh.Activate
c.Offset(0, x).PasteSpecial
With Selection
.ShapeRange.LockAspectRatio = msoFalse
.Height = c.Height - 4
.Width = c.Offset(0, x).Width - 4
.Left = c.Offset(0, x).Left + (c.Offset(0, x).Width - .Width) / 2
.Top = c.Offset(0, x).Top + (c.Offset(0, x).Height - .Height) / 2
End With
shbar.Cells.Interior.Color = 16777215
shbar.Cells.UnMerge
Next c
Application.DisplayAlerts = False
shbar.Delete
Application.DisplayAlerts = True
End Sub

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です