Need to automate the creation of QR Codes? Excel and VBA can help with that! Here's how to do it in less than 15 lines of code.
What we're looking to do is have a URL in a cell and then we're going to use a function that we create in VBA call Google APIs to create the code. Here's a video that explains the whole process of creating a user defined function in VBA that will create QR Codes:
Code to create QR Codes in Excel with VBA
Open up your Visual Basic editor and insert the following code and then save. To call the function, type =GETQRCODES(Cell Address) where Cell Address is the address of the cell which contains a URL that you want to send your user to.
Function GETQRCODES(QRCode As String)
Dim URL As String
URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & QRCode
ActiveSheet.Pictures.Insert(URL).Select
With Selection.ShapeRange(1)
.Name = "QR_CODE_" & QRCode
.Left = Application.Caller.Left + 2
.Top = Application.Caller.Top + 2
End With
GETQRCODES = ""
End Function
Explanation Of What The Code Does
Here's what the code above does:
First, it constructs the URL for the QR code generation service. Then, it inserts the QR code image into the active sheet.
It sets the name of the picture to "QR_CODE_" followed by the URL that the QR code sends the user to.
Then, it positions the QR code image 2 units to the right and down from the calling cell.
Finally, it returns an empty string because the function doesn't need to return anything else.
Hope you find this useful and do follow us for more useful automation tips and tricks.
Comments
Post a Comment