将EXCEL中的多个PDF打印到一个文件中

mspsb9vt  于 2023-02-10  发布在  其他
关注(0)|答案(1)|浏览(168)

我有这个代码。它循环通过和改变一个值,然后打印,并重复。问题是,我的pdf只是最后一个循环值,它不添加每个变化作为一个单独的工作表在我的pdf。

Private Sub CommandButton1_Click()


For x = 1 To 100 'increase the 100 to a larger number if you ever have more than 100 sheets

If Sheets("Sheet2").Range("T" & x).Value = "" Then Exit Sub

Sheets("Sheet2").Range("F4").Value = Sheets("Sheet2").Range("T" & x).Value

Sheets("Sheet2").Range("F3").Value = Sheets("Sheet2").Range("U" & x).Value

'For Each ws In ActiveWorkbook.Worksheets

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF

                               

Next

End Sub

尝试了代码,预期20张的PDF,但只得到了1,我的范围的最后一个值。

nhjlsmyf

nhjlsmyf1#

这对我想要的很有效。

Private Sub CommandButton1_Click()

For x = 1 To 100 'increase the 100 to a larger number if you ever have more than 100 sheets

If Sheets("Sheet2").Range("T" & x).Value = "" Then Exit Sub

Sheets("Sheet2").Range("F4").Value = Sheets("Sheet2").Range("T" & x).Value

Sheets("Sheet2").Range("F3").Value = Sheets("Sheet2").Range("U" & x).Value

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\test" & x & ".pdf"

Next

End Sub

相关问题