【发布时间】:2015-04-22 18:04:11
【问题描述】:
下面的代码非常适合创建从工作表 3 到名为“发布”的工作表的 PDF,同时忽略任何隐藏的工作表。它为每个工作表创建一个单独的 PDF。这与用户单击的形状相关联,然后系统会提示您选择一个文件夹来保存所有 PDF。
我正在尝试更改下面的代码以执行完全相同的操作,除了为工作表 3 和“发布”之间的每个可见工作表创建一个 PDF。
我一直在研究代码,想知道是否有人知道完成此操作的最佳方法?
Sub SaveAllPDF()
Dim i As Integer
Dim Fname As String
Dim TabCount As Long
TabCount = Sheets("Post").Index
'Set the TabCount to the last cell you want to PDF
Dim dialog As FileDialog
Dim path As String
Set dialog = Application.FileDialog(msoFileDialogFolderPicker)
dialog.AllowMultiSelect = False
If dialog.Show = -1 Then
path = dialog.SelectedItems(1)
' Begin the loop.
For i = 3 To TabCount
'Set i = the number of the first sheet you want to PDF in order from left to right To TabCount
If Sheets(i).Visible <> xlSheetVisible Then
Else
With Sheets(i)
Fname = .Range("C15") & " " & .Range("E13") & "-" & .Range("B1")
'The Fname above is equaling the cells that the PDF's filename will be
'The folder directory below is where the PDF files will be saved
.ExportAsFixedFormat Type:=xlTypePDF, FileName:=path & "\" & Fname, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
End If
Next i
Call Shell("explorer.exe" & " " & path & "\", vbNormalFocus)
'This opens the folder where the PDFs are saved
End If
End Sub
【问题讨论】:
-
如果它们不在Sheet3和Sheet“Post”之间,我确实可以通过按名称隐藏所有Sheets来实现这一点。一种手动解决方法,好像将来添加了一张需要隐藏在工作表 3 之外的工作表以“发布”,然后我必须进入并添加要隐藏的代码。我仍在寻找答案,如果找到,我会发布解决方案!