QR Code creator

judgejustin

Board Regular
Joined
Mar 3, 2014
Messages
143
So this may be way beyond what's possible, but, I want to be able to run a macro that does these things, Makes a Workbook sharable from OneDrive that is also editable to the user and create a QR Code and paste it into the workbook. The reason for the pasting is because I will be printing it out as a label and I need users to be able to scan the QR code and edit some of the data. I will be linking this to a button in the workbook as well. Below is what I last worked on. I am no professional by any means so there may be stuff in here that is not necessary and there are a lot of notes in it so that I can remeber what I was doing. Feel free to edit any of it or start from scratch if this is useless. Also, this was actually programmed to get the QR from an online generator and not to pull it from OneDrive so at a minimum that would need to be changed.
Also, I am perfectly open to suggestions of how to do this better if anyone has a suggestion. If it would help I can also explain more in depth what this will be doing and how it will be used.

Thanks in advance.

Code:
Sub MakeSharableAndGenerateQRCode()
    Dim ws As Worksheet
    Dim qrURL As String
    Dim sharableLink As String
    Dim http As Object
    Dim qrImage As Object
    Dim imageURL As String
    Dim imagePath As String
    Dim cellForQRCode As Range

    ' Set worksheet and define cell for QR Code placement
    Set ws = ThisWorkbook.Sheets(1) ' Modify if not the first sheet
    Set cellForQRCode = ws.Range("A10") ' Adjust cell for QR placement
    
    ' Generate sharable link (This assumes the workbook is saved on a cloud/network location)
    If ThisWorkbook.Path = "" Then
        MsgBox "Please save the workbook to a network or cloud location first.", vbExclamation
        Exit Sub
    End If
    sharableLink = ThisWorkbook.FullName ' You can customize this to point to an actual sharable link

    ' Use Google Chart API to generate the QR code
    qrURL = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" & sharableLink & "&choe=UTF-8"

    ' Download the QR code image
    Set http = CreateObject("MSXML2.XMLHTTP")
    http.Open "GET", qrURL, False
    http.Send
    
    If http.Status = 200 Then
        ' Save the image to a temporary location
        imagePath = Environ("TEMP") & "\QRCode.png"
        With CreateObject("ADODB.Stream")
            .Type = 1
            .Open
            .Write http.responseBody
            .SaveToFile imagePath, 2
            .Close
        End With

        ' Insert the QR code image into the worksheet
        Set qrImage = ws.Pictures.Insert(imagePath)
        With qrImage
            .Left = cellForQRCode.Left
            .Top = cellForQRCode.Top
            .Width = cellForQRCode.Width
            .Height = cellForQRCode.Height
        End With

        MsgBox "QR Code generated and added to the sheet!", vbInformation
    Else
        MsgBox "Failed to generate QR code. Check your internet connection.", vbExclamation
    End If
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,225,397
Messages
6,184,716
Members
453,254
Latest member
topeb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top