Excel VBA: Open Source QR Code Generator

In this article, I’ll show you how to use Excel VBA as an open-source QR code generator.


Excel VBA: Open Source QR Code Generator (Quick View)

Function Generate_QR(QR_Value As String)
    Dim URL As String
    Dim MyCell As Range
    Set MyCell = Application.Caller
    URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & QR_Value
    On Error Resume Next
      ThisWorkSheet.Pictures("My_QR_CODE_" & MyCell.Address(False, False)).Delete
    On Error GoTo 0
    ThisWorkSheet.Pictures.Insert(URL).Select
    With Selection.ShapeRange(1)
     .Name = "My_QR_CODE_" & My_Cell.Address(False, False)
     .Left = MyCell.Left + 5
     .Top = MyCell.Top + 5
    End With
    GenerateQR = ""
End Function

vba qr code generator open source


Download Practice Workbook

Download this practice workbook to exercise while you are reading this article.


5 Easy Steps to Generate Open Source QR Code Using Excel VBA

Here, I have an Excel workbook with a worksheet containing some values in a column. The next column is left open to generate OR codes based on the values.

Data Set to Generate Open Source QR Code Using Excel VBA

Our objective today is to generate QR codes based on the values using Excel VBA.


⧪ Step 1: Opening Visual Basic Window

Press ALT+F11 on your keyboard to open the Visual Basic window.

Opening VBA Window to Generate Open Source QR Code Using Excel VBA


⧪ Step 2: Inserting a New Module

Go to the Insert > Module option in the toolbar. Click on Module. A new module called Module1 will be inserted.


⧪ Step 3: Putting the VBA Code

Put the following VBA Code in the module.

⧭ VBA Code:

Function Generate_QR(QR_Value As String)
    Dim URL As String
    Dim MyCell As Range
    Set MyCell = Application.Caller
    URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & QR_Value
    On Error Resume Next
      ThisWorkSheet.Pictures("My_QR_CODE_" & MyCell.Address(False, False)).Delete
    On Error GoTo 0
    ThisWorkSheet.Pictures.Insert(URL).Select
    With Selection.ShapeRange(1)
     .Name = "My_QR_CODE_" & My_Cell.Address(False, False)
     .Left = MyCell.Left + 5
     .Top = MyCell.Top + 5
    End With
    GenerateQR = ""
End Function

vba qr code generator open source


⧪ Step 4: Saving Workbook as a .xlsm File

Next, return to the workbook and save it as an Excel Macro-Enabled Workbook.

Saving Workbook to Generate Open Source QR Code Using Excel VBA


⧪ Step 5: The Output

We’ve created a user-defined function called Generate QR. It takes a string value as the argument and returns a QR code in response to that value.

Come back to your worksheet and enter this formula in a cell:

=Generate_QR(D2)

Here, D2 is a cell that contains a value. You enter your one.

Then click ENTER. An open-source QR code will be entered into the cell.

Output to Generate Open Source QR Code Using Excel VBA

Do the same for the rest of the cells.

Read More: How to Scan QR Code to Excel Spreadsheet


Things to Remember

We are generating the QR codes from some open sources on the internet. Therefore, the internet connection of your computer must remain active for the process to accomplish smoothly.


Conclusion

Therefore, this is the process to generate open-source QR codes using VBA in Excel. Do you have any questions? Feel free to ask us. And don’t forget to visit our site ExcelDemy for more posts and updates.


Related Articles

Rifat Hassan

Rifat Hassan

Hello! Welcome to my profile. Here I will be posting articles related to Microsoft Excel. I am a passionate Electrical Engineer holding a Bachelor’s degree in Electrical and Electronic Engineering from the Bangladesh University of Engineering and Technology. Besides academic studies, I always love to keep pace with the revolution in technology that the world is rushing towards day by day. I am diligent, career-oriented, and ready to cherish knowledge throughout my life.

2 Comments
  1. Hi Rifat – this doesn’t seem to work. The Google charts API may be the issue. Have you tested this recently?
    thanks,
    Ashley

    • Hello, ASHLEY!
      Thanks for your comment.
      Yes. Unfortunately, the google charts API is currently broken. You can use the following API which I updated in the article.

      https://chart.googleapis.com/chart?chs=100×100&&cht=qr&chl=

      Try out this code below.

      Function GenerateQR(qrcode_value As String)
          Dim URL As String
          Dim My_Cell As Range 
          Set My_Cell = Application.Caller
          URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & qrcode_value
          On Error Resume Next
            ActiveSheet.Pictures("My_QR_CODE_" & My_Cell.Address(False, False)).Delete
          On Error GoTo 0
          ActiveSheet.Pictures.Insert(URL).Select
          With Selection.ShapeRange(1)
           .Name = "My_QR_CODE_" & My_Cell.Address(False, False)
           .Left = My_Cell.Left + 5
           .Top = My_Cell.Top + 5
          End With
          GenerateQR = ""  
      End Function

      Hope this will help you!
      Good Luck!

      Regards,
      Sabrina Ayon
      Author, ExcelDemy
      .

Leave a reply

ExcelDemy
Logo