With Microsoft Excel, you can use it for helping with your work, and in this post, I have a new function that shows you you can create a QR code or Barcode with an easy VBA code. And you can scan or print it out for your work. For this article, I will show you how to generate QR codes using Visual Basic Application code (VBA) with Google APIs. Note that your PC should be connected internet before generation because Google APIs generate QR codes for you online.
Excel Contents:
So If you want to create a function and generate QR codes in Excel, please follow with me step by step :
Create QR code using VBA code in Excel
Before you can create generator function, you should be :
1 – Open Excel
2 – Create a table for putting value and QR code picture
Adding your text at Value column for generator values
3 – Press Alt + F11 for open VBA editor
Go on the Insert tab and choose Module for module creation. And after module creation so you can coding create a generator function.
The following coding:
Function GenerateQR(qrcode_value As String)
Dim URL As String
Dim My_Cell As Range
Set My_Cell = Application.Caller
' Google Chart API for generating QR codes is no longer supported or has been deprecated URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & qrcode_value
URL = "https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=" & 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
4 – After you finish your coding, you go on the Excel Workbook and call function and press Enter
=GenerateQR(Your_Value_Cell)
Final Result :
Note : Your PC should be connect internet, Save your Excel file as Excel Macro – Enabled Workbook (*.xlsm)
Thanks for your useful sharing
Thanks
WHATS THE VBA CODE FOR MULTIPLE CELL IN ONE QR CODE AT A TIME? PLEASE
I’m creating multiple vCard QR codes using Excel VBA and need to add a logo to the QR image, how can I do that? Here’s what I currently have for the QR Code in VBA.
Sub generateQRCode()
strURL = “https://chart.googleapis.com/chart?cht=qr”
For intRow = 2 To 5
strFname = Trim(ThisWorkbook.Sheets(“Contact_Info”).Range(“A” & intRow).Text)
strLname = Trim(ThisWorkbook.Sheets(“Contact_Info”).Range(“B” & intRow).Text)
strEmail = Trim(ThisWorkbook.Sheets(“Contact_Info”).Range(“C” & intRow).Text)
strCompn = Trim(ThisWorkbook.Sheets(“Contact_Info”).Range(“D” & intRow).Text)
strVCF = “”
strVCF = strVCF & “BEGIN:VCARD” & Chr(10)
strVCF = strVCF & “VERSION:3.0” & Chr(10)
strVCF = strVCF & “N:” & strLname & “;” & strFname & Chr(10)
strVCF = strVCF & “ORG:” & strCompn & Chr(10)
strVCF = strVCF & “FN:” & strFname & Chr(10)
strVCF = strVCF & “EMAIL:” & strEmail & Chr(10)
strVCF = strVCF & “END:VCARD”
ThisWorkbook.Sheets(“Contact_Info”).Range(“I” & intRow) = strVCF
strChs = “&chs=174” & “x” & “174”
strCh1 = “&chl=”
strFinalURL = strURL & strChs & strCh1 & strVCF
Dim pic As Object, sh As Shape
ActiveSheet.Range(“J” & intRow).Select
Set pic = ActiveSheet.Pictures.Insert(strFinalURL)
pic.Top = ActiveSheet.Range(“J” & intRow).Top
pic.Left = ActiveSheet.Range(“J” & intRow).Left
Next
End Sub
QR Code is taking small data, that is around 25 character. What should I do to insert 40-50 character data.
Yes, you can insert.
QR is taking only approx 25 characters. What is the code for 45- 50 characters input.