我研究出了直接调用API接口,只要有网络就能用,快束生成二维码,我模版中是A列数据生成二维码在C列,二维码的大小可以自已调。
代码如下:
核心点就是调用API,生成二维码,内容模版是从第1列取值,可根据自身需求调整。
Sub 批量生成二维码()
Dim cell As Range
Dim pic As Shape
For Each pic In ActiveSheet. Shapes
If pic. Type <>8 And pic. Type <>12 Then'删除图片,不删除宏按钮 And pic. Type <>12
pic. Delete
End If
Next
N = Cells(65536, 1). End(xlUp). Row
For i =2 To N
’调用API或控件生成二维码
With ActiveSheet.Pictures.Insert("http://api.qrserver.com/v1/create-qr-code/?data=" & Cells(i,1))
’调整位置等属性
插入图片到第三列对应单元格1
. Left = Cells(i,3). Left
. Top = Cells(i, 3). Top
. ShapeRange. LockAspectRatio = msoTrue
. Width = Cells(i,③). Width -2’留出边距
End With
ActiveSheet. Range(" Al"). Select
Application. CutCopyMode = False
Next i
ActiveSheet. Pictures. ShapeRange. Height =50
ActiveSheet. Pictures. ShapeRange. Width =50
End Sub