保存时自动执行此操作

时间:2017-01-02 13:04:21

标签: vba excel-vba excel

如何在每次保存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

Picture of the VBA-Code

1 个答案:

答案 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