Exportar como PDF un documento con VBA Excel
Maestro me podría apoyar con mi código de favor, funciona bien genera la información que se solicita pero la manda directo a la impresora y me gustaría me abriera la ventana para exportarlo en PDF o me preguntara IMPRESION o PDF. ¿Podria apoyarme por favor?
Adjunto mi codigo.
Private Sub ImprimirInforme()
Dim objExcel As Application
Dim RutaArchivo As String
Dim Texto As String
Dim fila As Long
Dim Final As Long
Set objExcel = CreateObject("Excel.Application")
With objExcel
RutaArchivo = ThisWorkbook.Path & "\Informe_tmp.xlsx"
If IsFileOpen(RutaArchivo) Then
MsgBox "El libro debe estar cerrado para proceder."
Exit Sub
Else
'
With .Workbooks.Open(RutaArchivo)
If Reimpresion = 1 Then GoTo Reimprimir
.Worksheets("Hoja1").Range("Área_de_impresión").ClearContents
fila = 9
Do While .Worksheets("Hoja1").Cells(9, 1) <> ""
fila = fila + 3
Loop
Final = fila
.Worksheets("Hoja1").Range("A3").Value = "INFORME DE CONSUMIBLES UTILIZADOS"
.Worksheets("Hoja1").Range("B4").Value = "PERIODO DE CONSULTA"
.Worksheets("Hoja1").Range("A5").Value = "Periodo Inicial:"
.Worksheets("Hoja1").Range("B5").Value = Me.txtFecha1
.Worksheets("Hoja1").Range("A6").Value = "Periodo Final"
.Worksheets("Hoja1").Range("B6").Value = Me.txtFecha2
.Worksheets("Hoja1").Range("A8").Value = "CONCEPTO"
.Worksheets("Hoja1").Range("B8").Value = "CANTIDAD"
For i = 0 To Me.ListBox1.ListCount - 1
.Worksheets("Hoja1").Cells(Final, 1) = Me.ListBox1.List(i, 0) 'Cantidad
.Worksheets("Hoja1").Cells(Final, 2) = Me.ListBox1.List(i, 1) & " " & Me.ListBox1.List(i, 2) 'Descripción
Final = Final + 1
Next
'Establecer área de impresión y enviar al impresor.
Reimprimir:
.Worksheets("Hoja1").PageSetup.PrintArea = "Área_de_impresión"
.Worksheets("Hoja1").PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
'Call PDFActiveSheet
.Close SaveChanges:=True
End With
End If
.Quit
End With
End Sub
1 Respuesta
Respuesta de Programar Excel
1