我目前正在尝试导出一些工作表(从1到500),基于包含某个单词ie的单元格:“打印”到单个PDF文档。
下面是我到目前为止尝试做的,然而,即使第8,9和10张包含“打印”在单元格A1我仍然得到消息“PDF文件未创建”。
Sub Save_Sheets_As_PDF()
Dim sheetsInPDF As Long
Dim replaceSelected As Boolean
Dim ws As Worksheet
Dim PDFfileName As String
With ThisWorkbook
sheetsInPDF = 0
replaceSelected = True
For Each ws In .Worksheets
If LCase(ws.Range("A1").Value) = "Print" Then
ws.Select replaceSelected
replaceSelected = False
sheetsInPDF = sheetsInPDF + 1
End If
Next
If sheetsInPDF > 0 Then
PDFfileName = Worksheets("QUOTE").Range("B6") & ".pdf"
.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfileName, _
Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox "Created '" & PDFfileName & "' containing " & sheetsInPDF & " Elevations"
Else
MsgBox "PDF file not created"
End If
.Worksheets(1).Select True
End With
End Sub
任何帮助将不胜感激。即使完全替换此代码可能是最好的。TIA布拉德
1条答案
按热度按时间xriantvc1#
这行代码。。
...将始终被评估为False。请尝试以下操作...
要指定路径,请尝试...
实际上,如果Worksheets(“QUOTE”)位于ThisWorkbook中,请尝试以下操作...