如何关闭来自 Excel-VBA 脚本调用的 .exe 的错误消息? [英] How to close an error message from an .exe called from a Excel-VBA script?

查看:49
本文介绍了如何关闭来自 Excel-VBA 脚本调用的 .exe 的错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从 vba 调用外部 .exe 文件时,像这样:

Sub RunEXE()将 wsh 调暗为对象SetCurrentDirectory "\path" '设置目录Set wsh = VBA.CreateObject("program.exe ""\pathargument""", WindowStyle:=1, waitonreturn:=True)

是否可以直接从 VBA 关闭错误窗口?

代码调用程序并正确运行 .exe 并生成对我有用的所有数据,但要将数据返回到我的工作表中,我必须确认此窗口(因为 waitonreturn=true):

我的 VBA 代码似乎无法影响违规行为,但它不会影响我执行代码所需的计算所需的 .exe 部分.与其深入研究外部软件的内存访问冲突,我希望通过直接从 VBA 代码中解决问题来回避问题.

如果我在该错误消息上单击确定",就我的代码而言,一切都是完美的.我不需要 .exe 来保存导致错误的文件,而且我已经有了我需要的数据.

是否可以从我的 excel-VBA 代码中消除来自外部软件的错误窗口?

注意:错误来自 .exe 程序,而不是来自 excel 本身.

解决方案

这是sendkeys的一个简单例子,它会打开记事本,然后发送一个回车键:

Sub SendEnterToNotepad()有申请外壳记事本.exe",3发送键{ENTER}"结束于结束子

When calling a external .exe file from vba, like this:

Sub RunEXE()
Dim wsh As Object
SetCurrentDirectory "\path" 'Set Directory
Set wsh = VBA.CreateObject("program.exe ""\pathargument""", WindowStyle:=1, waitonreturn:=True)

Is it possible to close error windows directly from VBA?

The code calls the program and correctly runs the .exe and produces all of the data that is useful to me, but to get the data back to my sheet I have to okay this window (since waitonreturn=true):

The violation appears to be something I can't impact from my VBA code, but it is not impacting the section of the .exe I need in order to do the calculations required by my code. Instead of delving into the world of memory access violation of an external piece of software, I am hoping to side step the problem by okaying it direct from the VBA code.

If I click okay on that error message everything is perfect as far as my code is concerned. I don't need the .exe to save the files causing the error, and I already have the data I need.

Is it possible to dismiss an error window from external software from my excel-VBA code?

NOTE: The error comes from the .exe program, not from excel itself.

解决方案

This is a simple example of sendkeys, which will open notepad and then send an Enter key:

Sub SendEnterToNotepad()
    With Application
        Shell "Notepad.exe", 3
        SendKeys "{ENTER}"
    End With
End Sub

这篇关于如何关闭来自 Excel-VBA 脚本调用的 .exe 的错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆