我在此網站上發現以下代碼「將Excel文件另存爲CSV」有什麼方法可以幫助您在特定時間自動運行此代碼(每晚11:00晚上),並保存文件名爲當前日期(hr2015-05-05),任何幫助將不勝感激。由於在特定時間運行VBA代碼
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFileName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
Set Sourcewb = ActiveWorkbook
TempFileName = Sourcewb.FullName + ".csv"
'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
'Save the new workbook and close it
With Destwb
.SaveAs Filename:=TempFileName, FileFormat:=xlCSV, ConflictResolution:=xlLocalSessionChanges
.Close SaveChanges:=False
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub
編輯固定標籤問題
你可以訪問使用Windows任務調度程序? – Sam
絕對最好的方法是利用Powershell和Windows Task Scheduler。 –
是的我可以訪問Windows任務計劃程序,但是Task Scheduler如何運行VBA代碼並使用當前日期保存文件? – user3877643