0% found this document useful (0 votes)
58 views2 pages

QR 0

This document contains VBA code to generate and insert QR codes into an Excel worksheet. It includes subroutines to: 1) Create QR codes in a loop for multiple cells by calling the CrearQRIndividual subroutine. 2) Generate an individual QR code by downloading the image from a URL, inserting it into the sheet, and adjusting cell formatting. 3) Clear any existing images on the sheet before generating new QR codes.

Uploaded by

Ad52 Toñito
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views2 pages

QR 0

This document contains VBA code to generate and insert QR codes into an Excel worksheet. It includes subroutines to: 1) Create QR codes in a loop for multiple cells by calling the CrearQRIndividual subroutine. 2) Generate an individual QR code by downloading the image from a URL, inserting it into the sheet, and adjusting cell formatting. 3) Clear any existing images on the sheet before generating new QR codes.

Uploaded by

Ad52 Toñito
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#If VBA7 And Win64 Then

Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _


Alias "URLDownloadToFileA" ( _
ByVal pCaller As LongPtr, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As LongPtr, _
ByVal lpfnCB As LongPtr _
) As Long
#Else

#End If

Sub CrearQRMasivo()
Dim n&, i&
LimpiarImagenes
With wGenerador
n = .Range("A" & Rows.Count).End(xlUp).Row
For i = 4 To n
CrearQRIndividual .Range("A" & i)
Next
End With
End Sub

Sub CrearQRIndividual(Valor As Range)


Dim Link$, Ruta$, QR As Object
Dim lado&, izqui&, nTop&
'Descargo el código QR
If Valor.Value = Empty Then
Exit Sub
End If

Link = "http://chart.apis.google.com/chart?ch..." & Valor.Value & "&chld=H|


0"
Ruta = ThisWorkbook.Path & "\chart.png"
URLDownloadToFile 0, Link, Ruta, 0, 0
'-----------------

'Ingreso la imagen
Set QR = ActiveSheet.Pictures.Insert(Ruta)
Kill Ruta
With wGenerador
nTop = .Range("B" & Valor.Row).Top
lado = .Range("B" & Valor.Row).Width
izqui = .Range("B" & Valor.Row).Left
With QR
.Top = nTop
.Width = lado
.Left = izqui
End With
.Range("B" & Valor.Row).RowHeight = lado
End With
'-----------------

End Sub

Sub LimpiarImagenes()
Dim imagen As Picture
For Each imagen In ActiveSheet.Pictures
imagen.Delete
Next
wGenerador.Range("A4", "A" & Rows.Count).RowHeight =
wGenerador.Range("A1").RowHeight
End Sub

You might also like