繁体   English   中英

Excel任务计划程序。 我收到错误消息“ Microsoft Excel已停止工作”

[英]Excel task scheduler. I get the error “Microsoft Excel has stopped working”

我在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 Task Scheduler运行包含此宏的excel文件。 它会按程序创建一个excel文件,并关闭除excel应用程序外的所有工作簿。 但是,此后,我收到错误消息“ Microsoft Excel已停止工作”。

为什么会这样呢? 关于如何解决此问题的任何建议?

弄清楚了。 在任务计划程序中,在“属性”->“设置”下,取消选中“如果正在运行的任务在请求时未结束,请强制停止”复选框

停止获取错误!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM