用c#closuresvbamacros打开的模式

我正在创build一个在excel表单中执行vbamacros的ac#程序。

在vbamacros完成执行后,它显示一个模式窗口,不允许继续执行我的程序。

有什么办法可以closures那个模式窗口吗? 或者甚至有可能?

我努力了:

appExcel.DisplayAlerts = false; appExcel.EnableEvents = false; 

但它没有工作。

注:我没有访问vbamacros代码。

最好的祝福!

这里是一个“轻量级”的解决scheme,从我的答案中修改到纯粹的VBA类似的问题。 它使用两个Win32 API函数: FindWindowSendMessage

 [DllImport("user32.dll")] static extern int FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam); // This function endlessly waits for a window with the given // title and when found sends it a WM_CLOSE message (16) public static void killMbox(Object windowTitle) { for (int h = 0; h == 0;) { Thread.Sleep(1000); h = FindWindow(null, windowTitle.ToString()); if (h != 0) SendMessage(h, 16, 0, 0); } } static void Main(string[] args) { Thread mboxKiller = new Thread(killMbox); // Excel message-boxes usually have title "Microsoft Excel". // Change if your message-box has a different title mboxKiller.Start("Microsoft Excel"); Application xlApp = new Application(); Workbook wb = xlApp.Workbooks.Open("C:/SO/SO.xlsm"); xlApp.Visible = true; xlApp.Run("doMessageBox"); // launches a macro that displays a message box // now the mboxKiller will close that mbox, code here proceeds // ... xlApp.Quit(); } }