按特定顺序打印多个Excel工作表 [英] Print Multiple Excel sheets in a specific order
问题描述
我正在尝试从Excel工作簿中打印/发布多张工作表,但顺序是特定的.我使用的代码与此处相同,但不是按照输入数组的顺序打印,而是从最左边的页面打印到最右边的页面.
I am trying to print/publish multiple sheets from Excel workbook, but in a specific order. I use the same code used here but it is not printing in the order I inputted into my array and alternatively is printing from leftmost sheet to the rightmost sheet.
我想按特定顺序打印纸页.我选择了要打印的顺序,但是,它从最左边的工作表开始打印,并按照它们在工作簿中的方式向右打印.如何使它们按照我在数组中输入的顺序打印.
I would like to print the sheets in a specific order. I selected the order that I wanted to print, however, it printed from left most sheet and going to right in the way they were in the workbook. How can I make them print in the order that I inputted in the array.
我选择了
ThisWorkbook.Sheets(Array("GIT 100", "GIT 399", "CheckList GIT 400", "TCCC", "4.1")).Select
但是我得到了"4.1","CheckList GIT 400","GIT 399","TCCC","GIT 100"作为已发布的文档.
But I got "4.1","CheckList GIT 400","GIT 399","TCCC","GIT 100" as the published document.
任何帮助将不胜感激.
推荐答案
仅循环:
Sub Kakeda()
ary = Array("GIT 100", "GIT 399", "CheckList GIT 400", "TCCC", "4.1")
For Each a In ary
Sheets(a).ExportAsFixedFormat Type:=xlTypePDF
Next a
End Sub
EDIT#1:
此版本将分别保存 .pdf 文件:
This version will save the .pdf files separately:
Option Explicit
Sub Kakeda()
Dim ary
Dim a As Variant, fp As String
ary = Array("GIT 100", "GIT 399", "CheckList GIT 400", "TCCC", "4.1")
fp = ActiveWorkbook.Path
For Each a In ary
Sheets(a).ExportAsFixedFormat Type:=xlTypePDF, Filename:=fp & "\" & a & ".pdf"
Next a
End Sub
EDIT#2:
此版本将创建一个单个pdf
Option Explicit
Sub Kakeda3_TheSequel()
Dim ary
Dim a As Variant, fp As String
ary = Array("GIT 100", "GIT 399", "CheckList GIT 400", "TCCC", "4.1")
fp = ActiveWorkbook.Path
For Each a In ary
Sheets(a).Move after:=Sheets(Sheets.Count)
Next a
ThisWorkbook.Sheets(ary).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF
End Sub
这篇关于按特定顺序打印多个Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!