Como exportar en Pdf mi recibo hecho en excel con vba en excel

Buenas tardes Dante, que tal? Será que me podrías ayudar con mi archivo, tengo una planilla de sueldos y  quisiera saber si existe una forma de exportarlo en pdf al hacer clic con un boton de comando vba el cual le nombré "imprimir en PDF", si me podrías ayudar, desde ya muchas gracias.

Respuesta
2

El código completo para imprimir, visualizar y enviar a PDF es est:

Private Sub CommandButton6_Click()
'Por.Dante Amor
    imprimir "pdf"
End Sub
Private Sub CommandButton7_Click()
'Por.Dante Amor
    imprimir "recibo"
End Sub
Private Sub CommandButton8_Click()
'Por.Dante Amor
    imprimir "impresora"
End Sub
Sub imprimir(opcion)
'Por.DAM
    If ComboBox2 = "" Then
        MsgBox "Ingresa el aÑO", vbExclamation, "Trebolsoft System"
        ComboBox2.SetFocus
        Exit Sub
    End If
    If ComboBox1 = "" Then
        MsgBox "Ingresa el Mes", vbExclamation, "Trebolsoft System"
        ComboBox1.SetFocus
        Exit Sub
    End If
    selec = False
    For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) Then
            selec = True
            Exit For
        End If
    Next
    If selec = False Then
        MsgBox "Selecciona un sector", vbExclamation, "Trebolsoft System"
        ListBox1.SetFocus
        Exit Sub
    End If
    Set h7 = l1.Sheets("Impresion")
    h7.Cells.Clear
    If valida_archivo() Then
        u = 1
        For i = 2 To h2.Range("A" & Rows.Count).End(xlUp).Row
            For j = 0 To ListBox1.ListCount - 1
                If ListBox1.Selected(j) Then
                    If h2.Cells(i, "A") = ListBox1.List(j) Then
                        h1.[G13] = h2.Cells(i, "C")
                        h1.[C13] = h2.Cells(i, "R")
                        h1.[E7] = CONVERTIRNUM(h2.Cells(i, "R"), False)
                        h1.Rows(1 & ":" & 15).Copy h7.Range("A" & u)
                        u = u + 16
                        h7.HPageBreaks.Add Before:=h7.Range("A" & u)
                    End If
                End If
            Next
        Next
        Select Case opcion
        Case "impresora"
            If MsgBox("La impresora está preparada:", vbYesNo, "") = vbYes Then
                h7.PrintOut Copies:=1, Collate:=True
            End If
        Case "recibo"
            UserForm2.Hide
            h7.PrintPreview
            h3.Activate
            UserForm2.Show
        Case "pdf"
            ruta = l1.Path
            For j = 0 To ListBox1.ListCount - 1
                If ListBox1.Selected(j) Then
                    arch = arch & ListBox1.List(j) & "-"
                End If
            Next
            If CheckBox1 Then
                arch = "todoslossectores-"
            End If
            arch = arch & ComboBox1 & "-" & ComboBox2
            h7.ExportAsFixedFormat Type:=xlTypePDF, _
                Filename:=ruta & "\" & arch & ".pdf", _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, OpenAfterPublish:=False
            h3.Activate
            MsgBox "Impresión enviada a PDF", vbInformation, "Trebolsoft System"
        End Select
        l2.Close False
    Else
        MsgBox "El archivo no existe", vbCritical, "Trebolsoft System"
        ComboBox1.SetFocus
    End If
End Sub

1 respuesta más de otro experto

Respuesta
1

Usa el siguiente código:

ThisWorkbook.ExportAsFixedFormat type:=xlTypePDF, Filename:=“testPDF”, IncludeDocProperties:=True, OpenAfterPublish:=True

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas