利用控件生成二维码

Sub 生成二维码()
    Dim wb As Workbook
    Dim sht As Worksheet
    Set wb = Application.ThisWorkbook
    Set sht = wb.Worksheets(1)
    'Randomize
    With sht
        '删除旧条码控件
        .Shapes.SelectAll
        Selection.Delete
        For i = 1 To 20
            Set obj = .OLEObjects.Add(ClassType:="BARCODE.BarCodeCtrl.1")  '新增控件
            With obj
                .Left = sht.Cells(i, 3).Left + 2                          '控件的属性
                .Top = sht.Cells(i, 3).Top + 2
                .Width = 50
                .Height = 50
                .Object.Style = 11 '二维码
                .Object.ShowData = 1
                .Object.Value = Cells(i, "B").Value
                .Name = i
                .Select
                'Sht.Shapes.Item(obj.Name).CopyPicture
                Selection.CopyPicture
                sht.Cells(i, 4).Select
                sht.PasteSpecial Format:="图片(png)", Link:=False, DisplayAsIcon:=False
                .Delete
            End With
            DoEvents
        Next i
    End With
End Sub

 

posted @ 2023-09-03 23:49  wangway  阅读(28)  评论(0编辑  收藏  举报