|
楼主 |
发表于 2024-9-20 13:02
|
显示全部楼层
Sub SaveWorkbookAsPDFInSameFolder()
Dim savePath As String
' 获取当前工作簿的路径
savePath = ThisWorkbook.Path
' 拼接文件名和路径,使用工作簿的名称作为PDF的文件名
savePath = savePath & "\" & Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - Len(".xlsx")) & ".pdf"
' 将当前工作簿另存为PDF
ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=savePath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
' 可选:添加消息框提示保存成功
MsgBox "PDF文件已保存到: " & savePath
End Sub
|
|