I have a template in a work sheet and the data to be filled in another sheet. I have the code to fill the template but it prints as separate PDFs. But, I need it to be in a single PDF file. File name can be anything, doesn't matter. How do I modify this Excel VBA code to do this?
Sub GenerateDataSheets()
Row = 4
Do Until IsEmpty(Worksheets("Descriptions").Cells(Row, 1))
Sheets("Template").Range("U3") = Worksheets("Descriptions").Cells(Row, 1)
Sheets("Template").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & Worksheets("Descriptions").Cells(Row, 1)
Row = Row + 1
Loop
MsgBox "DataSheets have been generated."
End Sub
Why not first just add all the data to the list, then print? I think this may work for you:
Sub GenerateDataSheets()
Row = 3
Do Until IsEmpty(Worksheets("Descriptions").Cells(Row + 1, 1))
Sheets("Template").Range("U" & Row) = Worksheets("Descriptions").Cells(Row + 1, 1)
Row = Row + 1
Loop
Sheets("Template").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & Worksheets("Descriptions").Cells(3, 1)
MsgBox "DataSheets have been generated."
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.