1
當發現應接收按鍵的正確進程時,通過過濾父進程ID號 來標識進程。 此應用程序是一個Excel工作簿。在此應用程序 內運行一個宏需要按鍵。宏的提供者不能更改此行爲。如何查找和使用進程ID向C#中的Excel應用程序發送按鍵過程ID
此宏用戶窗體顯示宏完成時由於手動輸入要求而禁止自動化。
我已經嘗試了幾種不同的方法來發送返回鍵,但他們失敗了。 最有前途的是以下:
[DllImport("User32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
static extern int SetForegroundWindow(IntPtr hWnd);
//...then at the bottom of my script
//p is the Excel process selected from a bunch of Excel workbooks
IntPtr ptrFF = p.Handle;
SetForegroundWindow(ptrFF);
SendKeys.Send("{w 3}"); //<- it falls over at this stage
的錯誤信息是:
「的SendKeys無法在此應用中,因爲應用程序是不是 處理Windows消息運行要麼更改應用程序來處理消息, 或。使用SendKeys.SendWait方法。「
如果我使用
SendKeys.SendWait("{w 3}");
命令的話,好像沒事了,但按鍵沒有得到其所需的目的地莫名其妙。
您是否有任何想法如何通過發送鍵或其他方式使用Excel宏查找此問題的解決方法?