How to close an error message from an .exe called from a Excel-VBA script?

旧城冷巷雨未停 提交于 2019-12-24 07:59:37

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/47771171/how-to-close-an-error-message-from-an-exe-called-from-a-excel-vba-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!