如何在每次保存ecxel工作表时运行此代码?
Sub export_pdf()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"E:\09-Prozessvisualisierung.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True,IgnorePrintAreas:=False,OpenAfterPublish:=True
End Sub
我已经尝试过了。但是没有用。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sub export_pdf()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"E:\09-Prozessvisualisierung.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False,OpenAfterPublish:=True
End Sub
答案 0 :(得分:-1)
将整个代码写入Workbook_BeforeSave
事件。
(注意:如果可以提供帮助,我建议不要使用ActiveSheet
。)
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"E:\09-Prozessvisualisierung.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False
End Sub