Generate QR codes for your application

You might have a need to generate QR codes for your application. Here is one way to do so.

You've seen these all over the place. I see them at bus stops, on billboards and flyers:

QR code example

I guess they're supposed to mean something. QR-Server has a free API for creating these images. All we need to do is call the following URL:

http://api.qrserver.com/v1/create-qr-code/

Two parameters are required: size and data

So a sample API call looks like this:

http://api.qrserver.com/v1/create-qr-code/?size=200x200&data=Example

The value for the data parameter is supposed to be urlencoded, but it didn't seem to make a difference when I tested it. Then again, these images all look the same to me.

Sample UserForm

I created a sample userform for creating your own QR codes. You specify the size (up to 200px) and the text you want, and it displays the QR code in a WebBrowser Control.

The control changes size depending on the size of the image, however to be practical it will not go above 200px.

Here's how it looks when I use the name of this website:

QR Code userform

This is what happens when you press the Get QR Code button:

Private Sub GetQR_Click()

  On Error GoTo ErrorHandler

  Dim url As String
  Dim size As String
  Dim text As String
  Dim windowSize As Long

  size = Me.SizeText.Value
  text = Me.TextValue.Value

  If LenB(text) <> 0 Then
    url = Replace(url, "Example", URLEncode(text))
  Else  ' no text, exit
    GoTo ProgramExit
  End If

  ' default window size and url
  windowSize = 210
  url = BASE_URL
  
  If LenB(size) <> 0 Then
    If IsNumeric(size) Then
      If CLng(size) <= 200 Then
        url = Replace(BASE_URL, "200", size)
        windowSize = CLng(size) + 10
      End If
    End If
  End If

  With Me.WebBrowserCtl
    .Height = windowSize
    .Width = windowSize
    .Navigate url
  End With

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & " - " & Err.Description
  Resume ProgramExit
End Sub

Download sample userform

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »


Related Articles:


Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 2 Comment(s) on Generate QR codes for your application:

  1. Thanks for the post, your sample spreadsheet vba code has an error. the statement "url = BASE_URL" is in the wrong place, it keeps resetting the text back to "Example", move it up above the "url = Replace(url, "Example", URLEncode(text))" . That is why all of the QR codes look the same… Thanks!

    • Thank you, I did a lot of cutting and pasting in that procedure, I must have messed it up. I thought I debugged it but I guess not! I'll update the workbooks and upload them again shortly.

This article is closed to any future comments.
Random Data Generator