是否可以修改此代码以打印特定纸张列表的几个pdf文件?
Sub printselection()
Dim rng As Range
Dim wks As Worksheet
Dim arr() As String
Dim i As Long: i = 0
Dim x As Integer
For x = 1 To 3
For Each rng In Sheets("Consolidated").Range(Cells(x, x), Cells(x, x))
If Trim(rng.Value) <> "" Then
On Error Resume Next
Set wks = Nothing
Set wks = Sheets(rng.Value)
On Error GoTo 0
If wks Is Nothing Then
MsgBox "Sheet " & rng.Value & " does not exist"
Else
ReDim Preserve arr(i)
arr(i) = wks.Name
i = i + 1
End If
End If
Next rng
Dim printSheets As Variant
printSheets = arr
Worksheets(printSheets).PrintOut Preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=True, PrToFileName:=PSFileName
Next x
End Sub
我正在学习,因为我使用vba .....它只适用于A列,并且挂在最后一行,并希望它会在移动到下一列X时请求文件名。这里是列表名称的示例(我想将每列工作表名称打印到不同的pdf文件)
A B C
CA 10 - 50 Area 1 CO 10 - 50 Area 1 GA 10 - 50 Area 1
CA 10 - 50 Area 2 CO 10 - 50 Area 2 GA 10 - 50 Area 2
CA 10 - 50 Area 3 CO 10 - 50 Area 3 GA 10 - 50 Area 3
CA 10 - 50 Area 4
CA 10 - 50 Area 5
(A栏是CA,B栏是CO,C栏是GA)
答案 0 :(得分:0)
尝试循环播放printSheets
数组中的每个工作表:
For Each itm In printSheets
Worksheets(itm).PrintOut Preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=True, PrToFileName:=PSFileName
Next itm