如何运行Excel宏而不显示VBA运行时错误提示的VB脚本?

2026-05-06 13:031阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计350个文字,预计阅读时间需要2分钟。

如何运行Excel宏而不显示VBA运行时错误提示的VB脚本?

我想在VB脚本中运行Excel宏,但没有VBA就会在运行时给出错误提示,即宏有未捕获的运行时错误。理想情况下,我想捕获实际的运行时错误消息,但又不希望与对话框交互。

我想从VB脚本中运行Excel宏,但是没有VBA就会给出运行时错误提示,即使宏有未捕获的运行时错误.

理想情况下,我想捕获实际的运行时错误消息,但我很高兴能够在不与对话框交互的情况下恢复脚本.

这是我所说的最简单的例子.

test.vbs:

Option Explicit Dim Excel: set Excel = CreateObject("Excel.Application") Dim wb: set wb = Excel.Workbooks.Open("C:\Temp\test.xls") On Error Resume Next Excel.run "Hello" On Error Goto 0 wb.Close Excel.Quit

在名为test.xls的Excel电子表格的module1中:

Option Explicit Sub Hello() Dim x As Integer x = 1 / 0 ' Just causing an error for this example's purposes End Sub

关于这个问题背后的动机的简短解释.这是一个自动化任务,除了我无法更改需要自动化的宏的代码,因此我无法控制我调用的宏是否会有未捕获的运行时错误.

Stackoverflow上有许多关于使用VB脚本运行Excel宏的问题,但是我无法找到能够抑制VBA运行时错误提示的任何地址.

请在Sub rountine之后输入错误继续下一步

选项明确

如何运行Excel宏而不显示VBA运行时错误提示的VB脚本?

Sub Hello() On Error Resume Next ' Please include the error statement after sub routine. Dim x As Integer x = 1 / 0 ' Just causing an error for this example's purposes End Sub

本文共计350个文字,预计阅读时间需要2分钟。

如何运行Excel宏而不显示VBA运行时错误提示的VB脚本?

我想在VB脚本中运行Excel宏,但没有VBA就会在运行时给出错误提示,即宏有未捕获的运行时错误。理想情况下,我想捕获实际的运行时错误消息,但又不希望与对话框交互。

我想从VB脚本中运行Excel宏,但是没有VBA就会给出运行时错误提示,即使宏有未捕获的运行时错误.

理想情况下,我想捕获实际的运行时错误消息,但我很高兴能够在不与对话框交互的情况下恢复脚本.

这是我所说的最简单的例子.

test.vbs:

Option Explicit Dim Excel: set Excel = CreateObject("Excel.Application") Dim wb: set wb = Excel.Workbooks.Open("C:\Temp\test.xls") On Error Resume Next Excel.run "Hello" On Error Goto 0 wb.Close Excel.Quit

在名为test.xls的Excel电子表格的module1中:

Option Explicit Sub Hello() Dim x As Integer x = 1 / 0 ' Just causing an error for this example's purposes End Sub

关于这个问题背后的动机的简短解释.这是一个自动化任务,除了我无法更改需要自动化的宏的代码,因此我无法控制我调用的宏是否会有未捕获的运行时错误.

Stackoverflow上有许多关于使用VB脚本运行Excel宏的问题,但是我无法找到能够抑制VBA运行时错误提示的任何地址.

请在Sub rountine之后输入错误继续下一步

选项明确

如何运行Excel宏而不显示VBA运行时错误提示的VB脚本?

Sub Hello() On Error Resume Next ' Please include the error statement after sub routine. Dim x As Integer x = 1 / 0 ' Just causing an error for this example's purposes End Sub