Code
Private Sub CommandButton2_Click()
'This macro opens the SaveAs option with the defult file path "you have to set this file path below" coverts the whole sheet into .pdf file format
'And opens the .pdf to view <-- you can disable the view after covert option with lower code: OpenAfterPublish:=False
Dim newfn As Variant
pdfName = ActiveSheet.Range("h12")
'copy invoice to new workbook
ChDir "E:\bkk\mydir\dda\16-17\inv" 'This is where you set a defult file path.
'ActiveSheet.Copy
'newfn = "E:\bkk\mydir\dda\16-17\inv" & Range("h12").Value & ".xlsx"
'ActiveWorkbook.SaveAs newfn fileformat: = xlopenxmlworkbook
fileSaveName = Application.GetSaveAsFilename(pdfName, _
fileFilter:="PDF Files (*.pdf), *.pdf")
If fileSaveName <> False Then
ActiveSheet.Range("a5:m44").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
fileSaveName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End If
ActiveWorkbook.SaveAs "E:\bkk\mydir\dda\16-17\inv" & Sheet1("h12") & ".xlsx", FileFormat:=51
End Sub
Display More