+ Reply to Thread
Results 1 to 11 of 11

VBA Coding for QR Code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    174

    VBA Coding for QR Code

    Hello,
    I want to generate QR code from the value (Text and number) which will be there in one Cell of excel sheet. QR Code should be updated when the value of the cell changes. QR should not be updated automatically, there should be update button which can be used/clicked for updating QR code.

    Thanks in advance

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: VBA Coding for QR Code

    Maybe https://www.extendoffice.com/documen...e-qr-code.html
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    174

    Re: VBA Coding for QR Code

    Thanks for reply. Can you please provide VBA code in which source cell and output cell will be pre-determine in VBA code? Also it will be great if i need not to add any add-ons for this. To generate QR code, i will click button which will create QR code. So if possible give button for that which will be micro assigned. Thanks.

  4. #4
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    174

    Re: VBA Coding for QR Code

    As per this, i will have to download barcode control. I just want to say that, is it possible to have simple VBA code for QR code which will not be needed any download?

  5. #5
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    174

    Re: VBA Coding for QR Code

    Somewhere on internet i found below code but this code automatically update info. Also size of QR code and cell reference is difficult to understand. Can you alter this code so that i can use it manually (Not automatically) and create QR code at desired cell location?

    Option Explicit
    
    Function URL_QRCode_SERIES( _
        ByVal PictureName As String, _
        ByVal QR_Value As String, _
        Optional ByVal PictureSize As Long = 150, _
        Optional ByVal DisplayText As String = "", _
        Optional ByVal Updateable As Boolean = True) As Variant
    
    Dim oPic As Shape, oRng As Excel.Range
    Dim vLeft As Variant, vTop As Variant
    Dim sURL As String
    
    Const sRootURL As String = "https://chart.googleapis.com/chart?"
    Const sSizeParameter As String = "chs="
    Const sTypeChart As String = "cht=qr"
    Const sDataParameter As String = "chl="
    Const sJoinCHR As String = "&"
    
    If Updateable = False Then
        URL_QRCode_SERIES = "outdated"
        Exit Function
    End If
    
    Set oRng = Application.Caller.Offset(, 1)
    On Error Resume Next
    Set oPic = oRng.Parent.Shapes(PictureName)
    If Err Then
        Err.Clear
        vLeft = oRng.Left + 4
        vTop = oRng.Top
    Else
        vLeft = oPic.Left
        vTop = oPic.Top
        PictureSize = Int(oPic.Width)
        oPic.Delete
    End If
    On Error GoTo 0
    
    If Len(QR_Value) = 0 Then
        URL_QRCode_SERIES = CVErr(xlErrValue)
        Exit Function
    End If
    
    sURL = sRootURL & _
           sSizeParameter & PictureSize & "x" & PictureSize & sJoinCHR & _
           sTypeChart & sJoinCHR & _
           sDataParameter & UTF8_URL_Encode(VBA.Replace(QR_Value, " ", "+"))
    
    Set oPic = oRng.Parent.Shapes.AddPicture(sURL, True, True, vLeft, vTop, PictureSize, PictureSize)
    oPic.Name = PictureName
    URL_QRCode_SERIES = DisplayText
    End Function
    Function UTF8_URL_Encode(ByVal sStr As String)
       
        Dim i As Long
        Dim a As Long
        Dim res As String
        Dim code As String
        
        res = ""
        For i = 1 To Len(sStr)
            a = AscW(Mid(sStr, i, 1))
            If a < 128 Then
                code = Mid(sStr, i, 1)
            ElseIf ((a > 127) And (a < 2048)) Then
                code = URLEncodeByte(((a \ 64) Or 192))
                code = code & URLEncodeByte(((a And 63) Or 128))
            Else
                code = URLEncodeByte(((a \ 144) Or 234))
                code = code & URLEncodeByte((((a \ 64) And 63) Or 128))
                code = code & URLEncodeByte(((a And 63) Or 128))
            End If
            res = res & code
        Next i
        UTF8_URL_Encode = res
    End Function
    
    Private Function URLEncodeByte(val As Integer) As String
        Dim res As String
        res = "%" & Right("0" & Hex(val), 2)
        URLEncodeByte = res
    End Function

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: VBA Coding for QR Code

    I''m sorry, I can't help you. I don't have this control on my system and have no need of it, so I won't be installing it.

    The instructions seem fairly clear. You need to try and follow them and see how far you get. Come back if you get stuck and I'm sure someone will be able to offer some advice.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: VBA Coding for QR Code

    The code does not mean anything to me. However, they are all functions, so I assume you use one, or more, of them in a cell, or cells, on the worksheet.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: VBA Coding for QR Code

    It would probably help everyone if you'd provided the link to the site where you found the code.

    I'm guessing this is it: https://sites.google.com/site/e90e50...ode-with-excel

    Looks as though you put the function, URL_QRCode_SERIES, in a cell and the QR Code will be created in the next cell. The output cell is determined by Set oRng = Application.Caller.Offset(, 1), so you can probably adjust those offsets.

    It all looks pretty straightforward.

  9. #9
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    174

    Re: VBA Coding for QR Code

    Quote Originally Posted by TMS View Post
    It would probably help everyone if you'd provided the link to the site where you found the code.

    I'm guessing this is it: https://sites.google.com/site/e90e50...ode-with-excel

    Looks as though you put the function, URL_QRCode_SERIES, in a cell and the QR Code will be created in the next cell. The output cell is determined by Set oRng = Application.Caller.Offset(, 1), so you can probably adjust those offsets.

    It all looks pretty straightforward.
    THANKS FOR REPLY, this code works well but it slows down my excel file. It works on formula and hence continuously update QR code when i change value of any cell, i think because of this, it is slowing down my excel file. Do u have any solution for this? I have also tried Code given on https://stackoverflow.com/questions/...sing-excel-vba but and also good and do not slow down my file but when i try to save my excel file, file stop to responds and close down.


    If possible please give solutions to above problems. Thanks.

  10. #10
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    174

    Re: VBA Coding for QR Code

    Quote Originally Posted by TMS View Post
    It would probably help everyone if you'd provided the link to the site where you found the code.

    I'm guessing this is it: https://sites.google.com/site/e90e50...ode-with-excel

    Looks as though you put the function, URL_QRCode_SERIES, in a cell and the QR Code will be created in the next cell. The output cell is determined by Set oRng = Application.Caller.Offset(, 1), so you can probably adjust those offsets.

    It all looks pretty straightforward.
    Also it require internet connection. Can we do it in offline mode?

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: VBA Coding for QR Code

    Please stop quoting whole posts. No one else is joining in so you're just replying to me. Do NOT use "Reply With Quote": use "Post Quick Reply". If you need to make reference to specific text, just cut and paste it and use the Quote icon (to the left of the Code icon ( # ).

    If it's using a Google API, I guess you need to live with needing an Internet connection. Doubt there's anything you can do about that.

    I don't think I can offer any further advice. I wanted to point you in, hopefully, the right direction. Seems you're off and running, even though you haven't achieved the ideal solution ( yet ).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Code: Trouble coding multiple arguments to trigger
    By AlexShip in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2019, 08:25 AM
  2. [SOLVED] vba coding to bring account name for a code for a drop down list
    By srinivasan1965 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-10-2018, 02:25 PM
  3. Coding to Ignore if false between each part of a code..
    By aaaaaaiden in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2013, 10:46 AM
  4. get the color coding in conditional formatting using VBA code
    By ammupriyaa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2012, 07:13 AM
  5. [SOLVED] VBA code for converting set of item coding to full names and percentage
    By Seisouhen in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-01-2012, 08:47 AM
  6. coding error when trying to chanage code to work on same sheet but different area
    By jabjab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2011, 12:45 PM
  7. Help coding Logical function in VBA code
    By Wiggert in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2009, 12:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1