=IMAGE('https://api.qrserver.com/v1/create-qr-code/?size=150x150&data='&A2)
本例中,它的第1参数是qrserver.com的QR CODE API接口,可以公开、免费、稳定的生成二维码。
换句话说,我们把qrserver.com生成二维码的网址给它,剩下的事就让它去操心,咱们躺收其成就行了。
Sub GetQRCode()
Range('b1').Select
ActiveSheet.Pictures.Insert ('https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=' & Range('a1').Value)
End Sub
Sub GenerateQRCode()
Dim rng As Range, cell As Range
Dim shp As Shape, img As Picture, url As String
Application.ScreenUpdating = False
For Each shp In ActiveSheet.Shapes
If shp.Type = 11 Then shp.Delete
Next
Set rng = Range('A2:A' & Cells(Rows.Count, 'A').End(xlUp).Row)
rng.RowHeight = 60 '调整行高
rng.Offset(0, 1).ColumnWidth = 15 '调整隔壁列列宽
For Each cell In rng
If Len(cell.Value) Then
url = 'https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=' & cell.Value
Set img = ActiveSheet.Pictures.Insert(url, False)
With cell.Offset(0, 1)
img.Top = .Top + 3
img.Left = .Left + 3
img.Width = .Width
img.Height = .Height - 6
End With
End If
Next
Application.ScreenUpdating = True
MsgBox '处理完成。', , '公众号Excel星球'
End Sub
ActiveSheet.Pictures.Insert('https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=' & Range('a1').Value)
联系客服