VBA生成条形码并放到指定的单元格位置

VBA生成条形码并放到指定的单元格位置-LMLPHP

Sub 条形码生成()
Application.ScreenUpdating = False
subexit = 0
Call 检查条码位数
If subexit = 1 Then
    Exit Sub
End If
Call 清空数据
Dim i As Long       '行号
Dim X As String
Dim w As Worksheet
Set w = Worksheets("数据")
endrow = w.Range("A" & w.Cells.Rows.Count).End(xlUp).Row
Dim arr()
Dim brr()
arr = Array(4, 6, 7, 8, 6, 7, 8)
brr = Array(1, 1, 1, 1, 5, 5, 5)
Dim wf As Worksheet
    For i = 3 To endrow
        Worksheets("打印模板").Copy after:=Worksheets(Worksheets.Count)
        Set wf = Worksheets(Worksheets.Count)
        wf.Name = i - 2
        For j = 1 To 7
            With ActiveSheet.OLEObjects.Add(ClassType:="BARCODE.BarCodeCtrl.1")             '----插入条码
                .Name = "BarCodeCtrl" & j                      '----条码名称可以自定,这里以行号命名
                .Object.Style = 7                                      '----7”代表条码样式为“code 128”,
                .Object.ShowData = 0
                .Left = wf.Cells(arr(j - 1), brr(j - 1)).Left + 5 '----条码左边缘
                .Top = wf.Cells(arr(j - 1), brr(j - 1)).Top + 5   '----条码上缘位置
                .Height = 42.5                                    ' ----条码高度
                .Width = 150                                      ' ----条码宽度
                .Object.Value = w.Cells(i, j).Text                ' ----对生成的条码赋值,
            End With
        Next
    Next

Application.ScreenUpdating = True
w.Activate
MsgBox "条形码生成完成"
End Sub


08-30 05:23