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

问题描述

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

  Sub RunEXE()
Dim wsh作为对象
SetCurrentDirectory \\path\'设置目录
设置wsh = VBA.CreateObject( program.exe \\path\argument,WindowStyle: = 1,waitonreturn:= True)

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



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







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



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



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

解决方案

这是sendkeys的简单示例,它将打开记事本,然后发送Enter键:

  Sub SendEnterToNotepad()
应用程序
Shell Notepad.exe,3
SendKeys {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 ""\\path\argument""", 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中的错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 19:00
查看更多