我在工作表中有一个模板,并且要在另一个工作表中填写数据。我有填充模板的代码,但它打印为单独的PDF。但是,我需要它在一个PDF文件中。文件名可以是任何内容,无关紧要。如何修改此Excel VBA代码才能执行此操作?
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
答案 0 :(得分:0)
为什么不首先将所有数据添加到列表中,然后打印?我认为这可能适合你:
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