Here’s a quick preview of 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: 5 Easy Steps to Generate
We have an Excel workbook with a worksheet containing some values in a column. The next column is left open to generate QR codes based on the values.
Step 1 – Opening Visual Basic Window
- Press Alt + F11 on your keyboard to open the Visual Basic window.
Step 2 – Inserting a New Module
- Go to the Insert 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
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.
Step 4 – Saving Workbook as a .xlsm File
- Return to the workbook and save it as an Excel Macro-Enabled Workbook.
Step 5 – The Output
- Enter this formula in cell C3:
=Generate_QR(B3)
- Hit Enter. An open-source QR code will be entered into the cell.
- 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 an open-source library on the internet. You will need an internet connection to get the results.
Download Practice Workbook
Download this practice workbook to exercise while you are reading this article.
Related Articles
<< Go Back To QR Code in Excel | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!
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.
Hope this will help you!
Good Luck!
Regards,
Sabrina Ayon
Author, ExcelDemy.
Is it possible to get the QR code to have a label displayed either in the middle of the QR code or below it?
Hi XIONG YANG,
Thanks for your comment. I am replying on behalf of ExcelDemy. You can not add a label directly in the QR Code. But, you can add a label to the cell where you are inserting the QR Code by following these simple steps.
Step-01: Write the following VBA code in the module instead of the code that is provided in this article.
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 = ActiveCell.Offset(0, -1).Value
End Function
Now, Save the code and go back to your worksheet.
Step-02: Select the cells where you want the QR Codes >> go to the Home tab >> select Bottom Align.
Step-03: Select the cell where you want the QR Code >> write the following formula in that cell.
=GenerateQR(B5)
Next, press Enter and you will get the QR Code with the Label.
Step-04: Finally, get the QR Codes for other data in the same way.
I hope this will help you to solve your problem. Please let me know if you have other queries.
Regards
Mashhura,
ExcelDemy.
Why can not be made while character “+” in tthe text ?
Greetings George. I am replying on behalf of ExcelDemy. There was an issue with the code in the file. I have updated the file. This works perfectly fine for a “+” character in the text.
Hello, I have a problem with the script. It doesn’t download qrcode from google. Error #ARG!
Hello Smith,
Thanks for sharing your experience with us. The #ARG! error (Argument Error) in Excel generally occurs when a function or formula receives incorrect or invalid arguments. In the above code, I have noticed a few varibale name mismatches. Such as:
The function is defined as “Generate_QR” but it is assigned the name “GenerateQR” in the code. “My_Cell” should be “MyCell“. Also, The URL construction has double ampersands (“&&“) which are not needed.
As a result, the VBA script is returning these errors. Thanks for pointing out this to us. We greatly appreciate your feedback.
I have fixed the issues of the code. Try the below code instead:
Regards,
Yousuf Khan Shovon
Hi There,
If any update about the URL….??, Seemed, the link is broken
Thank’s
Valen
Hello Valen,
Can you mention the URL, please? In our site all URL’s of this article are working perfectly.
Regards
ExcelDemy
Hello,
is there a possibility that the data from all the cells is one QR code ?
Hello Aleksandar,
You can concatenate the cell values into a single string to get one QR code from different cell values.
You can use the following code:
Regards
ExcelDemy