2

Estou com o seguinte projeto:

inserir a descrição da imagem aqui

Quando clico no botão funciona perfeitamente, nenhum problema, mas eu queria q o QR Code fosse gerado na Planilha 2 por exemplo.

Abaixo o código do macro

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 Resposta 1

0

Apenas altere aqui o seu código:

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

Ou

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

Agora.. você poderia também colocar de maneira dinâmia dentro de sua função, adicionando mais um parâmetro da seguinte forma:

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)

E ao chamar sua função coloque o nome da planilha de destino como novo parâmetro:

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

Ou Crie uma nova linha com sua informação:

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

Espero ter ajudado!

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .