Hi,
I have a Word document like 100 pages and would like to save as PDF file saved by name as mentioned on first line in word document.
I saw a macro that basically creates a pdf out of each page individually and it works perfectly. I want to to save the document as PDF with the name on the first line as mentioned in word document.
I have tried to change the code but this is not working properly. The second records and the required text will not show in pdf file. can you please help me?
thank you in advance.
Sub SaveToPDF()
Dim I As Long
Dim xdlg As FileDialog
Dim xfolder As Variant
Dim xStart, xEnd As Integer
Dim docmultiple As Document
Dim strNewFileName As String
Dim iCurrentPage As Integer
Dim ipagecount As Integer
Dim rngpage As Range
Dim rngdoc As Range
Application.ScreenUpdating = False
Set docmultiple = ActiveDocument
Set rngpage = docmultiple.Range()
Set rngdoc = ActiveDocument.Content
Set xdlg = Application.FileDialog(msoFileDialogFolderPicker)
If xdlg.Show <> -1 Then Exit Sub
xfolder = xdlg.SelectedItems(1)
iCurrentPage = 1
ipagecount = docmultiple.Content.ComputeStatistics(wdStatisticPages)
Do Until iCurrentPage > ipagecount
If iCurrentPage = ipagecount Then
rngpage.End = ActiveDocument.Range.End
Else
Selection.GoTo wdGoToPage, wdGoToAbsolute, iCurrentPage
rngpage.End = Selection.Start
End If
strNewFileName = Empty
rngpage = iCurrentPage
strNewFileName = strNewFileName & Left(rngdoc.Paragraphs(1), _
Len(rngdoc.Paragraphs(1).Range.Text) - 1)
ActiveDocument.ExportAsFixedFormat OutputFileName:=xfolder & "" & strNewFileName, ExportFormat:=wdFormatPDF, Range:=wdExportCurrentPage
iCurrentPage = iCurrentPage + 1
Selection.GoTo wdGoToPage, wdGoToNext
rngpage.Collapse wdCollapseEnd
Loop
Application.ScreenUpdating = True
Exit Sub