用vba把excel文件发布转化为pdf格式文件

时间:2024-03-01 08:41:53

 

将工作薄每一个工作表导出为PDF文件。

 

Sub PDF()
 Dim asy As Worksheet
 Dim spath As String
 spath = Excel.ThisWorkbook.Path
 For Each asy In Excel.ThisWorkbook.Worksheets
 sName = spath & "\" & asy.Name & ".pdf"
 asy.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sName
 Next
End Sub

将当前工作表导出为PDF文件。

 

Sub PDF()
spatch = Excel.ThisWorkbook.Path
sName = spatch & "\" & ActiveSheet.Name & Format(Date, "yyyymmdd")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sName
End Sub

 

 

 VBA 参考文档

https://msdn.microsoft.com/zh-cn/VBA/Excel-VBA/articles/workbook-exportasfixedformat-method-excel