'*********************************************************************************
'Macro que exporta una hoja Excel a formato PDF.
'Versión mínima de Excel: 2010
'**********************************************************************************
'Parámetros:
'sheetname: Nombre de la hoja a exportar.
'pdfname: Nombre para el archivo PDF
Sub ExportaraPDF(sheetname As String, Optional pdfname As String)
' Guarda la hoja especificada o la hoja 1 como un archivo PDF
'
On Error GoTo errcontrol
If sheetname = "" Then
sheetname = Sheets(1).Name
End If
If pdfname = "" Then
pdfname = Left(ThisWorkbook.Name, InStr(ThisWorkbook.Name, ".xls")-1)
End If
Sheets(sheetname).Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & pdfname & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Range("A1").Select
Exit Sub
errcontrol:
MsgBox "Se ha producido un error al convertir la hoja " & sheetname & Err.Description
End Sub
'*********************************************************************************
'Macro que exporta un libro Excel a formato PDF.
'Versión mínima de Excel: 2010
'**********************************************************************************
'Parámetros:
'pdfname: Nombre para el archivo PDF
Sub ExportarLibroaPDF(Optional pdfname As String)
' Guarda el libro como un archivo PDF
'
On Error GoTo errcontrol
If pdfname = "" Then
pdfname = Left(ThisWorkbook.Name, InStr(ThisWorkbook.Name, ".xls") - 1)
End If
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & pdfname & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Range("A1").Select
Exit Sub
errcontrol:
MsgBox "Se ha producido un error al convertir el libro " & sheetname & Err.Description
End Sub
¿Le ha sido útil este artículo?
¡Qué bien!
Gracias por sus comentarios
¡Sentimos mucho no haber sido de ayuda!
Gracias por sus comentarios
Sus comentarios se han enviado
Agradecemos su esfuerzo e intentaremos corregir el artículo