【问题标题】:Excel task scheduler. I get the error "Microsoft Excel has stopped working"Excel 任务计划程序。我收到错误“Microsoft Excel 已停止工作”
【发布时间】:2015-06-08 07:04:47
【问题描述】:

我在 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 已停止工作”的错误。

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

【问题讨论】:

  • Sheet1 上有什么 - 任何按钮或控件?为什么不在代码的前面创建新工作簿并将值直接写入其中?
  • 工作表 1 为空。我可以尝试这样做

标签: vba excel scheduled-tasks


【解决方案1】:

想通了。在任务计划程序中,在属性 -> 设置下,我取消选中“如果正在运行的任务在请求时没有结束,则强制它停止”框

停止收到错误!

【讨论】:

    猜你喜欢
    • 2020-02-03
    • 1970-01-01
    • 2014-03-23
    • 2015-07-25
    • 2020-01-28
    • 2013-10-27
    • 2013-02-24
    • 1970-01-01
    • 2015-06-24
    相关资源
    最近更新 更多