我有以下代码,它最终为用户提供了“打印”工作表的选项
我想修改它。应该询问用户是否要“将其导出为 PDF”,如果他选择“是”,则应打开本机 Excel 另存为对话框(按 F12 时出现的对话框),其中“另存为类型”= PDF:
Sub sbHide_Rows_Based_On_Criteria_Optional_Print()
Dim lRow As Long
Dim iCntr As Long
Dim asn As Integer
With Sheets("QuoteSheet")
lRow = .Cells(Rows.Count, "L").End(xlUp).Row
For iCntr = lRow To 1 Step -1
If .Cells(iCntr, "L") = "Y" Then
.Rows(iCntr).Hidden = True
End If
Next iCntr
End With
answer = MsgBox("Do You Want a Printout?", vbYesNo + vbQuestion, "Print Sheet")
If answer = vbYes Then ActiveSheet.PrintOut
End Sub
答案1
这应该有效:
answer = MsgBox("Do you want to export to PDF?", vbYesNo + vbQuestion, "Export to PDF")
If answer = vbYes Then
fileSaveName = Application.GetSaveAsFilename("", fileFilter:="PDF (*.pdf), *.pdf")
If fileSaveName <> False Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
End If