Created
April 22, 2022 13:38
-
-
Save Koushikphy/29e37d7ed9cc1555e6b3b04e2ef6019a to your computer and use it in GitHub Desktop.
Save a doc in PDF with same name in same place
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub MacroSaveAsPDF() | |
'macro saves pdf either in the same folder where active doc is or in documents folder if file is not yet saved | |
' | |
Dim strPath As String | |
Dim strPDFname As String | |
strPDFname = ActiveDocument.Name | |
strPDFname = Left(strPDFname, InStr(strPDFname, ".") - 1) | |
If strPDFname = "" Then 'user deleted text from inputbox, add default name | |
strPDFname = "example" | |
End If | |
strPath = ActiveDocument.Path | |
If strPath = "" Then 'doc is not saved yet | |
strPath = Options.DefaultFilePath(wdDocumentsPath) & Application.PathSeparator | |
Else | |
'just add \ at the end | |
strPath = strPath & Application.PathSeparator | |
End If | |
ActiveDocument.ExportAsFixedFormat OutputFileName:= _ | |
strPath & strPDFname & ".pdf", _ | |
ExportFormat:=wdExportFormatPDF, _ | |
OpenAfterExport:=False, _ | |
OptimizeFor:=wdExportOptimizeForPrint, _ | |
Range:=wdExportAllDocument, _ | |
IncludeDocProps:=True, _ | |
CreateBookmarks:=wdExportCreateWordBookmarks, _ | |
BitmapMissingFonts:=True | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment