Option Explicit
Sub ExportSelectionToPDF()
If TypeName(Selection) <> "Range" Then
MsgBox "Please select a range of cells, and try again!", vbExclamation, "Selection"
Exit Sub
End If
Dim saveas_filename As Variant
saveas_filename = Application.GetSaveAsFilename( _
InitialFileName:=Application.DefaultFilePath & "\" & ActiveSheet.Name & ".pdf", _
filefilter:="PDF (*.pdf), *.pdf", _
Title:="Save As", _
ButtonText:="Save")
If saveas_filename = False Then Exit Sub
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveas_filename
MsgBox "Completed...", vbInformation, "Completed"
End Sub
InitialFileName:=Application.DefaultFilePath & "\" & ActiveSheet.Name & ".pdf", _
Option Explicit
Sub ExportRangeToPDF()
If TypeName(ActiveSheet) <> "Worksheet" Then
MsgBox "No worksheet is active!", vbExclamation, "Worksheet"
Exit Sub
End If
Dim saveas_filename As Variant
saveas_filename = Application.GetSaveAsFilename( _
InitialFileName:=Application.DefaultFilePath & "\" & ActiveSheet.Name & ".pdf", _
filefilter:="PDF (*.pdf), *.pdf", _
Title:="Save As", _
ButtonText:="Save")
If saveas_filename = False Then Exit Sub
Dim last_row As Long
last_row = Cells(Rows.Count, "A").End(xlUp).Row
Dim export_range As Range
Set export_range = Range("A1:P" & last_row)
export_range.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveas_filename
MsgBox "Completed...", vbInformation, "Completed"
End Sub