Generating 2D (PDF417 or QR) barcodes using Excel VBA

前端 未结 2 894
北恋
北恋 2020-12-14 22:53

I would like to generate a 2d barcode (PDF417 or QR codes) in an Excel cell using macros. Just wondering is there any free alternatives to paid libraries to do this?

2条回答
  •  醉梦人生
    2020-12-14 23:53

    I know this is quite an old and well-established post (though the very good existing answer has not been accepted yet), but I would like to share an alternative that I prepared for a similar post in StackOverflow in Portuguese using the free online API from QR Code Generator.

    The code is the following:

    Sub GenQRCode(ByVal data As String, ByVal color As String, ByVal bgcolor As String, ByVal size As Integer)
    On Error Resume Next
    
        For i = 1 To ActiveSheet.Pictures.Count
            If ActiveSheet.Pictures(i).Name = "QRCode" Then
                ActiveSheet.Pictures(i).Delete
                Exit For
            End If
        Next i
    
        sURL = "https://api.qrserver.com/v1/create-qr-code/?" + "size=" + Trim(Str(size)) + "x" + Trim(Str(size)) + "&color=" + color + "&bgcolor=" + bgcolor + "&data=" + data
        Debug.Print sURL
    
        Set pic = ActiveSheet.Pictures.Insert(sURL + sParameters)
        Set cell = Range("D9")
    
        With pic
            .Name = "QRCode"
            .Left = cell.Left
            .Top = cell.Top
        End With
    
    End Sub
    

    It gets the job done by simply (re)creating an image from the URL built from the parameters in the cells. Naturally, the user must be connected to the Internet.

    For example (the worksheet, with contents in Brazilian Portuguese, can be downloaded from 4Shared):

提交回复
热议问题