Excel - Create QR Code with data of 4 cells

4

Good,

I'm trying to create a document in Excel that will fetch the entered data for example (B1, B2, B3, B4) and with this data generate a QrCode. I do not have any software yet that creates QrCode. I do not know if they recommend one.

Thank you

    
asked by anonymous 24.02.2017 / 13:52

1 answer

3

As I previously commented , there are direct ways to do this in VBA and the VBA Macro Only project on github may help you. However, there is a fairly simple way to get what you want, if the spreadsheet user has access to the Internet .

Just use an online API like the QR Code Generator service. The following code uses this service to mount a URL with the desired parameters and get the image directly from the Internet:

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

I set up a worksheet to test and put the B3-B7 cell settings. The button has a macro that calls the above code as follows:

Sub GenButton_Click()

    GenQRCode Range("B4").Value, Range("B5").Value, Range("B6").Value, Range("B7").Value

End Sub

The result is this:

Thesampleworksheetcanbedownloadedfrom from 4Shared . The API used has other parameters, which can be accessed in the documentation .

    
24.02.2017 / 16:30