在Excel中用VB批量生成二维码

需要在excel中enable开发工具
在文件-> 选项 -> 自定义功能中,勾上开发工具,然后保存。

在开发工具Tab下,点击Visual Basic

Private Sub BarCodeCtrl1_GotFocus()
lastrow = Range("a10000").End(xlUp).Row

For i = 2 To lastrow
Cells(i, 5).Select
URL = "http://qr.liantu.com/api.php?text=" & Cells(i, 1) & Chr(10) & Cells(i, 2) & Chr(10) & 

Cells(i, 3) & Chr(10) & Cells(i, 4)

ActiveSheet.Shapes.AddPicture(URL, False, True, 1, 1, 100, 100).Select
Set Rng = Cells(i, 5)
With Selection
.Top = Rng.Top + 1
.Left = Rng.Left + 1
.Width = Rng.Width - 2
.Height = Rng.Height - 2
End With
Next

End Sub

免费生成二维码的API:
http://www.liantu.com/pingtai/

注意:
例子中的生成的二维码是一幅图,不会跟着前面的值得改变而改变。如果用映入的方式插入的图片只是引用而已,当图片被删除、移动时,excel文件中的图片将会找不到资源位置。
https://blog.csdn.net/g1418377085/article/details/71125033

猜你喜欢

转载自blog.csdn.net/WendyXu8230/article/details/89493271