Create image in another form

Asked

Viewed 74 times

2

I have the following project:

inserir a descrição da imagem aqui

When I click the button works perfectly, no problem, but I wanted q the QR Code was generated in Spreadsheet 2 for example.

Below the macro code

Sub GenQRCode(ByVal data As String, ByVal color As String, ByVal bgcolor As String, ByVal size As Integer)
On Error Resume Next

    For i = 1 To ActiveSheet.Pictures.Count
        If ActiveSheet.Pictures(i).Name = "QRCode" Then
            ActiveSheet.Pictures(i).Delete
            Exit For
        End If
    Next i

    sURL = "https://api.qrserver.com/v1/create-qr-code/?" + "size=" + Trim(Str(size)) + "x" + Trim(Str(size)) + "&color=" + color + "&bgcolor=" + bgcolor + "&data=" + data
    Debug.Print sURL

    Set pic = ActiveSheet.Pictures.Insert(sURL + sParameters)
    Set cell = Range("D9")



    With pic
        .Name = "QRCode"
        .Left = cell.Left
        .Top = cell.Top
    End With

End Sub


Sub GenButton_Click()

    GenQRCode Range("Plan2!B4").Value, Range("Plan2!B5").Value, Range("Plan2!B6").Value, Range("Plan2!B7").Value


End Sub

1 answer

0

Just change your code here:

Set pic = Plan2.Pictures.Insert(sURL + sParameters)

Or

Set pic = Sheets("Plan2").Pictures.Insert(sURL + sParameters)

Now.. you could also dynamically place within your function by adding one more parameter as follows:

Sub GenQRCode(ByVal data As String, ByVal color As String, ByVal bgcolor As String, ByVal size As Integer, ByRef PLANILHA_DESTINO As String)
' [...] seu código...
Set pic = Sheets(PLANILHA_DESTINO).Pictures.Insert(sURL + sParameters)

And when calling your function put the name of the destination sheet as new parameter:

 GenQRCode Range("Plan2!B4").Value, Range("Plan2!B5").Value, Range("Plan2!B6").Value, Range("Plan2!B7").Value, "Plan2"

Or Create a new line with your information:

 GenQRCode Range("Plan2!B4").Value, Range("Plan2!B5").Value, Range("Plan2!B6").Value, Range("Plan2!B7").Value, Range("Plan2!B8").Value

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.