PDA

View Full Version : Need help for Macro code to save a word document to pdf and rename it



austine_sam
04-14-2012, 07:32 AM
I have a word document full of letters and i need to save each page to PDF and the name of the saved PDF file should be based on the text in the document.

The format of the saved file should not change while being converted to a pdf.

I went through one of the code in this forum but when the file is getting saved the format of the letter is getting changed .

Please see code given below in one of the earlier threads .

sub yadda()
'

Dim oSection As Section
Dim r As Range
Dim TempDoc As Document
Dim FirstPara As String

For Each oSection In ActiveDocument.Sections
Set r = oSection.Range
r.End = r.End - 1
Set TempDoc = Documents.Add
With TempDoc
.Range = r
FirstPara = r.Paragraphs(1).Range.Text
FirstPara = Left(FirstPara, Len(FirstPara) - 1)
.SaveAs FileName:=FirstPara & ".doc"
.Close
End With
Set r = Nothing
Set TempDoc = Nothing
Next
End Sub

Tinbendr
04-16-2012, 06:49 AM
Try this instead.

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
ActiveDocument.Path & "\" & ActiveDocument.Name & ".pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False

austine_sam
04-19-2012, 08:16 AM
Thank you for your suggestion. It was useful