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?ch..." & 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
Download Practice Workbook
Download this practice workbook to exercise while you are reading this article.
How 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.
Our objective today is to generate QR codes based on the values using Excel VBA.
⧪ Step 1: Opening the 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 > 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?ch..." & 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
⧪ Step 4: Saving the Workbook as a .xlsm File
Next, return to the workbook and save it as an Excel Macro-Enabled Workbook.
⧪ 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.
Do the same for the rest of the cells.
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.
The post Excel VBA: Open Source QR Code Generator appeared first on ExcelDemy.