我是一名网络开发人员,所以对代码并不陌生,但我从不使用 VBA。我编写了一个宏,我认为它会自动将任何 .xslx 保存为 pdf(除了 .xslx 之外)在同一目录中。这是代码
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim myPath As String
Dim myFileName As String
myPath = ThisWorkbook.Path
myFileName = ThisWorkbook.Name
' Remove the .xlsx extension from the file name
myFileName = Left(myFileName, InStrRev(myFileName, ".") - 1)
' Save as PDF in the same directory
ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:=myPath & "\" & myFileName & ".pdf"
End Sub