Macro para Exportar Listbox a PDF

Hola buen día,

Favor su apoyo.
En un Formulario tengo un Listbox el cual me filtra datos de otro libro excel, hasta ahí todo bien. Ahora lo que quiero hacer es que mediante un botón me permita exportar los datos del Listbox hacia un Pdf. El ListBox está compuesto por 8 Columnas, y quisiera que en los encabezados del PDF vayan ciertos textos en cada columna, por ejemplo (Uno, Dos, Tres, etc)
Nota: Al momento de presionar el Botón para exportar tiene que aparecer la ventana de Guardar Como para poder especificar ruta y nombre del Archivo.

De antemano muchas gracias por el apoyo.

1 Respuesta

Respuesta
1

Te anexo la macro para el botón2

Private Sub CommandButton2_Click()
'Por.Dante Amor
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set h1 = Sheets.Add
    c = ListBox1.ColumnCount
    f = ListBox1.ListCount + 1
    h1.Range(h1.Cells(2, 1), h1.Cells(f, c)) = ListBox1.List
    h1.Range("A1:H1") = Array("Uno", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete", "Ocho")
    h1.Cells.EntireColumn.AutoFit
    '
    With Application.FileDialog(msoFileDialogSaveAs)
        .Title = "Exportar archivo a PDF"
        .AllowMultiSelect = False
        .FilterIndex = 25
        If .Show Then
            march = .SelectedItems(1)
            h1.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=march, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=True
        End If
    End With
    h1.Delete
    Unload Me
End Sub

Saludos.Dante Amor

Recuerda valorar la respuesta.

Hola Dante;

Muchas gracias, sólo dos últimos detalles, hay forma que me lo pueda imprimir de forma Horizontal y no en vertical? ya que del uno al cuatro sale en una hoja y del cinco al ocho en otra.  y lo otro es que del uno al ocho el texto esté en Negrita.

Gracias.

Listo! Te anexo los cambios.

Private Sub CommandButton2_Click()
'Por.Dante Amor
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set h1 = Sheets.Add
    c = ListBox1.ColumnCount
    f = ListBox1.ListCount + 1
    '
    H1. Range(h1. Cells(2, 1), h1.Cells(f, c)) = ListBox1. List
 h1. Range("A1:H1") = Array("Uno", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete", "Ocho")
    h1.Cells.EntireColumn.AutoFit
    h1.PageSetup.Orientation = xlLandscape
    h1.Range("A1:H1").Font.Bold = True
    '
    With Application.FileDialog(msoFileDialogSaveAs)
        .Title = "Exportar archivo a PDF"
        .AllowMultiSelect = False
        .FilterIndex = 25
        If .Show Then
            march = .SelectedItems(1)
            h1.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=march, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=True
        End If
    End With
    '
    h1.Delete
    Unload Me
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas