我在excel上运行以下宏来创建特定文件夹中的文件列表Auto_Open
Option Explicit
Sub Auto_Open()
Dim MyFolder As String
Dim MyFile As String
Dim NextRow As Long
Dim MyDateTime As Date
Dim MyDate As Date
MyFolder = "C:\Users\Folder\"
MyFile = Dir(MyFolder)
NextRow = 1
Do While Len(MyFile) > 0
MyDateTime = FileDateTime(MyFolder & MyFile)
MyDate = Int(MyDateTime)
If MyDate = Date Then
Cells(NextRow, "A").Value = MyFolder & MyFile
Cells(NextRow, "B").Value = MyDateTime
NextRow = NextRow + 1
End If
MyFile = Dir
Loop
Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Sheets("Sheet1").Copy Before:=wb.Sheets(1)
wb.SaveAs ThisWorkbook.Path & "\" & Format(Now, "yyyy-mm-dd") & "_FileList", FileFormat:=51
wb.Close
ThisWorkbook.Close SaveChanges:=False
End Sub
我计划每天通过Windows任务调度程序运行包含此宏的excel文件。它按编程创建一个excel文件,并关闭除excel应用程序之外的所有工作簿。但是,之后我收到“Microsoft Excel已停止工作”的错误。
为什么会这样?关于我如何解决这个问题的任何建议?
答案 0 :(得分:0)