Hi Guys, I have a WORD file which includes 100 job offers for employees. Every 2 page in the document belongs to 1 person so I wrote the following code to do so and save as PDF separately. like:
PAGE1.2 = PDF1
PAGE3.4 = PDF2
and so on..
The problem is renaming the files. If you check in the code where I specified "FirstPara" - That's where the naming the file is happening. Right now it will take the 3rd line of the first document only! it will not go to the next loop. I don't know how to connect it to "i" so it would iterate every time and select the 3rd line of next page.
Basically, it's a nested loop I think?
PLEASE HELPPPP!
Sub SaveAsSeparatePDFs()
Dim strDirectory As String, strTemp As String, ipgEnd As Integer
Dim iPDFnum As Integer, i As Integer
1:
strTemp = InputBox("How many pages is included?" & vbNewLine & "(ex: 60)")
ipgEnd = CInt(strTemp)
strDirectory = Environ("USERPROFILE") & "\Desktop"
iPDFnum = 1
For i = 1 To ipgEnd
Set r = ActiveDocument.Range
r.End = r.End - 1
FirstPara = r.Paragraphs(1).Range.Text
FirstPara = Left(FirstPara, Len(FirstPara) - 1)
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
strDirectory & "\JobOffer--" & iPDFnum & FirstPara & ".pdf", ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
wdExportFromTo, From:=i, To:=i + 1, Item:=wdExportDocumentContent, _
IncludeDocProps:=False, KeepIRM:=False, CreateBookmarks:= _
wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=False, UseISO19005_1:=False
iPDFnum = iPDFnum + 1
i = i + 1
Next i
End
End Sub