【发布时间】:2020-10-11 17:12:38
【问题描述】:
在 VBA 中,我可以使用 End 语句终止宏的执行,如下所示。
Sub DoSomeThing()
Dim test As Boolean
test = false
test = function()
If test Then
End 'Macro execution is terminated
End if
End Sub
我希望我的 C# DLL 包含具有相同效果的方法?我正在考虑以下几点。
public void DoSomething_CSharp()
{
var test = false;
test = Function();
if (test)
{
//Call a command here that terminates execution of the VBA macro that calls this method.
}
}
我意识到End 是一个 VBA 语句,但我不知道如何从 C# DLL 中访问 VBA 语句。 (正如这个问题所示,我是 C# 新手。)
【问题讨论】:
-
为什么不将布尔值返回到 VBA,然后从那里关闭?
-
使用System.Environment.Exit(0);
-
没有。您必须使用
throw new Exception("Macro aborted");来完成。制定更好的消息来告诉您的用户您决定忽略他们的命令的原因取决于您。