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宏查找此问题的解决方法?