jbiggar
03-16-2011, 08:44 PM
This is my first experience with vba/macros. I need help creating a macro to save a Word Document existing in a folder as a PDF in the same folder with the same file name. I tried using the macro recorder but it will only work with that specific file name as shown below:
Sub SaveAsPDF()
'
' SaveAsPDF Macro
'
'
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"Q:\namerica\Phoenix\workgrps\LAB\Public\CRN\1234567890\1234567890.pdf", _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
ChangeFileOpenDirectory _
"Q:\namerica\Phoenix\workgrps\LAB\Public\CRN\1234567890\"
End Sub
If anyone has any guidance for me to apply this macro so whenever I open a word document which is alreaady saved as the file name I want to save the pdf as in the active folder it will help me and possibly other out greatly.
Below is some code I was playing with. Not sure if it could be used.
Dim fname As String
fname = ActiveDocument.Name
If ActiveDocument.Name is a ".doc" or ".docx"
Then remove the .doc or .docx
fname = the ActiveDocumentName with the .doc or .docx extension stripped
Dim fpath As String
fpath = ActiveDocument.Path
fpath = fpath & "\" & fname
Sub SaveAsPDF()
'
' SaveAsPDF Macro
'
'
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"Q:\namerica\Phoenix\workgrps\LAB\Public\CRN\1234567890\1234567890.pdf", _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
ChangeFileOpenDirectory _
"Q:\namerica\Phoenix\workgrps\LAB\Public\CRN\1234567890\"
End Sub
If anyone has any guidance for me to apply this macro so whenever I open a word document which is alreaady saved as the file name I want to save the pdf as in the active folder it will help me and possibly other out greatly.
Below is some code I was playing with. Not sure if it could be used.
Dim fname As String
fname = ActiveDocument.Name
If ActiveDocument.Name is a ".doc" or ".docx"
Then remove the .doc or .docx
fname = the ActiveDocumentName with the .doc or .docx extension stripped
Dim fpath As String
fpath = ActiveDocument.Path
fpath = fpath & "\" & fname