假设从B1单元格取值,在A1单元格中生成二维码,
那么,代码如下↓
Sub genBarCode()'清除已有二维码Call clearBarCodeWith ActiveSheet.OLEObjects.Add(ClassType:="BARCODE.BarCodeCtrl.1").Object.Style = 11 '二维码样式.Object.Value = Range("B1").Value '二维码内容'二维码大小和单元格A1相同.Height = Cells(1, 1).Height.Width = Cells(1, 1).Width.Left = Cells(1, 1).Left.Top = Cells(1, 1).TopEnd With
End SubSub clearBarCode()Dim shp As ShapeFor Each shp In ActiveSheet.ShapesIf shp.Type = 12 Then shp.DeleteNext
End Sub
生成的二维码如下↓