我有一个带有按钮的模板,可以将Excel转换为PDF并将其保存到特定位置。此外,它会将我的excel文件移动到新位置并终止旧文件。我愿意接受更好的方法或任何改善这一点的建议。
Private Sub PDF_Click()
Dim strFilename As String
Dim rngRange As Range
Set rngRange = Worksheets("MRO").Range("C6")
strFilename = rngRange.Value & Format(Now(), " mm-dd-yyyy hh_mm AM/PM")
Sheets(Array("MRO")).Select
Sheets("MRO").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
"\\*change this to your path*\" & strFilename & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Path = "\\*change this to your path*\"
Dim thisWb As Workbook
Set thisWb = ActiveWorkbook
MyOldName = ActiveWorkbook.FullName
MyNewName = ActiveWorkbook.Name
ActiveWorkbook.SaveAs fileName:=Path & "\" & MyNewName
Kill MyOldName
ActiveWorkbook.Close
End Sub