vba打印pdf文件以获取特定的工作表列表 [英] vba print pdf files for specific list of sheets
本文介绍了vba打印pdf文件以获取特定的工作表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以修改此代码以为特定的工作表列表打印一些pdf文件?
Is it possible to modify this code to print a few pdf files for a specific list of sheets?
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文件中)
I am learning as I go with vba.....it works for just column A and gets hung up on the last line and was hoping it would ask for a file name as it moves to the next column X. Here is a sample of column sheet names ( I want to print each column of sheet names to a different pdf file)
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)
(column A is CA, column B is CO and column C is GA)
推荐答案
尝试循环遍历 printSheets
数组中的每张纸:
Try to loop for each sheet in your printSheets
array:
For Each itm In printSheets
Worksheets(itm).PrintOut Preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=True, PrToFileName:=PSFileName
Next itm
这篇关于vba打印pdf文件以获取特定的工作表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文