Create image in another form

2

I have the following project:

WhenIclickthebuttonitworksperfectly,noproblem,butIwantedtheQRCodetobegeneratedinSheet2forexample.

Belowthemacrocode

SubGenQRCode(ByValdataAsString,ByValcolorAsString,ByValbgcolorAsString,ByValsizeAsInteger)OnErrorResumeNextFori=1ToActiveSheet.Pictures.CountIfActiveSheet.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
    
asked by anonymous 01.09.2017 / 13:19

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 put dynamically inside 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 target worksheet as a 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 have helped!

    
01.09.2017 / 16:22