Dear All,
I do have a macro command that i record but the problem is i do want a dynamic file save location and i want the file name follow my excel file name because i usually will make a few copy of this excel file to be created as pdf file with different file name.Is there a solution for the below macro :
Sub PDF()
'
' PDF Macro
'
'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"P:\JERRY\Payment advice-15th\Payment Advice_2016-17\2016.10\STM Tech.pdf"
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
Application.WindowState = xlMinimized
End Sub
Macro Save to PDF In Excel
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Macro Save to PDF In Excel
Do you want to save the PDF file in the same folder as the Excel workbook?
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 516
- Joined: 21 Feb 2016, 02:52
Re: Macro Save to PDF In Excel
Hi Hans,
Yup. It's better if can save in the same place with the excel file.
Yup. It's better if can save in the same place with the excel file.
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Macro Save to PDF In Excel
Give this a try.
(Note: I could not test it as I don't have the PDF add-in installed on in Office).
(Note: I could not test it as I don't have the PDF add-in installed on in Office).
Code: Select all
Sub SaveToPDF()
Dim wbA As Workbook
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
On Error GoTo errHandler
Set wbA = ActiveWorkbook
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
'create default name for savng file
strFile = Split(ActiveWorkbook.Name, ".")(0) & ".pdf"
strPathFile = strPath & strFile
'export to PDF
wbA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& strPathFile, vbInformation
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file", vbExclamation
Resume exitHandler
End Sub
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 4StarLounger
- Posts: 516
- Joined: 21 Feb 2016, 02:52
Re: Macro Save to PDF In Excel
Hi Rudi,
Thanks Ya..It work great..
Thanks Ya..It work great..