Function URL_QRCode_SERIES( _
ByVal QR_Value As String, _
Optional ByVal PictureSize As Long = 100, _
Optional ByVal DisplayText As String = "QRCode >>", _
Optional ByVal Updateable As Boolean = True) As Variant
Dim PictureName As String
Dim oPic As Shape, oRng As Excel.Range
Dim vLeft As Variant, vTop As Variant
Dim sURL As String
Const sRootURL As String = "https://quickchart.io/qr?text="
If Updateable = False Then
URL_QRCode_SERIES = "outdated"
Exit Function
End If
PictureName = "QR-Code_" & DisplayText 'Application.Caller.Address
Set oRng = Application.Caller
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 & WorksheetFunction.EncodeURL(QR_Value)
Set oPic = oRng.Parent.Shapes.AddPicture(sURL, True, True, vLeft, vTop, PictureSize, PictureSize)
oPic.Name = PictureName
URL_QRCode_SERIES = DisplayText
End Function