在Excel VBA中,我打开一个Word应用程序和一个doc.我想确保文档和Word最后都关闭,即使出现错误.
我创建了一个错误处理程序On Error GoTo ErrorHandler,它有效.但是objDoc.Close当没有打开文档时运行失败(运行时错误424),objWord.Quit尽管我打电话,Sub也被中止了On Error Resume Next.
为什么On Error Resume Next不在那里工作?
(在VBA选项中,错误陷阱设置为"中断未处理的错误".)
Sub test()
On Error GoTo ErrorHandler
' Open doc in Word
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Open("not a valid doc.docx")
....
' Save and exit
objDoc.Save
objDoc.Close
objWord.Quit
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & vbLf & Err.Description
On Error Resume Next
' Exit
objDoc.Close SaveChanges:=False
objWord.Quit
On Error …Run Code Online (Sandbox Code Playgroud) 我构建了一个执行 PowerShell 脚本的 32 位 .NET DLL。我需要它能够以 64 位和32 位的方式交替运行脚本。
我已经知道如何使用命令行来做到这一点:
C:\Windows\Sysnative\cmd /c powershell -ExecutionPolicy ByPass "& 'script.ps1' arguments"
C:\Windows\SysWOW64\cmd /c powershell -ExecutionPolicy ByPass "& 'script.ps1' arguments"
Run Code Online (Sandbox Code Playgroud)
但是我需要能够使用 C# 的接口,无论是System.Management.Automation.PowerShell类还是System.Management.Automation.Runspaces.Pipeline类,以便异步收集脚本的输出。