I am new to VBA and tried to work on a code that can save multiple pages of word documents as a separate PDF.
I am not only struggling with the File name, currently, it is saving with Page no but I require it to be a specific field from a Word document.
I have added the screenshot of my word doc and the name of the file should be "User ID" and "Reminder 1 ( this is fixed value)".doc
This is my code
Sub SaveAsSeparatePDFs()
Dim I As Long
Dim xDlg As FileDialog
Dim xFolder As Variant
Dim xStart, xEnd As Integer
On Error GoTo lbl
Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
If xDlg.Show <> -1 Then Exit Sub
xFolder = xDlg.SelectedItems(1)
xStart = CInt(InputBox("Select Start Page No", "Information"))
xEnd = CInt(InputBox("Select End Page No", "Information"))
If xStart <= xEnd Then
For I = xStart To xEnd
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
xFolder & "\Reminder 1" & I & ".pdf", ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
wdExportFromTo, From:=I, To:=I, Item:=wdExportDocumentContent, _
IncludeDocProps:=False, KeepIRM:=False, CreateBookmarks:= _
wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=False, UseISO19005_1:=False
Next
End If
Exit Sub
lbl:
MsgBox "Enter right page number", vbInformation, "ERROR"
End Sub