简体   繁体   English

Excel VBA:能够创建和发送 Outlook 电子邮件,但希望自动单击公司安全弹出窗口上的“发送”按钮

[英]Excel VBA: Able to create and send Outlook e-mail, but want to automate clicking a "SEND" button on a corporate security pop-up

I have the following code in an Excel VBA module:我在 Excel VBA 模块中有以下代码:

With OutlookMail
    .To = "mickey.mouse@disney.com"
    .CC = ""
    .BCC = ""
    .Subject = "Ride Review"
    .Body = "Please make the Turbo Spinner an express-lane ride."
    .Attachments.Add Path
    .Send
    SendKeys "{Enter}"
end With 'OutlookMail

The code works fine and will send an e-mail as expected.该代码工作正常,并将按预期发送电子邮件。 However, when the ".Send" command is executed, my company requires employees to fill out an e-mail security tool and then click an additional "SEND" / "CANCEL" button ("SEND" is highlighted by default).但是,当执行“.Send”命令时,我公司要求员工填写一个电子邮件安全工具,然后点击一个额外的“SEND”/“CANCEL”按钮(“SEND”默认高亮显示)。 (NOTE: this is NOT a warning pop-up that has hundreds of post about it). (注意:这不是一个包含数百个帖子的警告弹出窗口)。 The problem becomes when this window pops-up I am unable to navigate away from pop-up (ie it retains focus and gives an audible 'ding' noise and flashes the pop-up when you try to click on another area of the desktop).当此 window 弹出窗口时,问题就出现了,我无法离开弹出窗口(即,当您尝试单击桌面的另一个区域时,它会保持焦点并发出可听见的“叮”声并闪烁弹出窗口) . As such, I am not able to use the SendKeys function in VBA since Excel is no longer the active window and I am unable to continue to step through the code until I click "SEND" / "CANCEL" with my mouse. As such, I am not able to use the SendKeys function in VBA since Excel is no longer the active window and I am unable to continue to step through the code until I click "SEND" / "CANCEL" with my mouse. In fact, the 'SendKeys "{Enter}"' command places a return in the module code after I click "SEND"/"CANCEL" and continue stepping through the code (as expected).事实上,在我单击“SEND”/“CANCEL”并继续单步执行代码(如预期的那样)后,“SendKeys "{Enter}"' 命令会在模块代码中返回一个返回值。 I have searched online to no avail for something similar.我在网上搜索过类似的东西无济于事。 I am not sure there is a way to do this with Excel VBA given the fact that the code stops running until "SEND"/"CANCEL" is clicked, but perhaps there is a way to force it.我不确定有没有办法用 Excel VBA 来做到这一点,因为代码停止运行直到单击“发送”/“取消”,但也许有一种方法可以强制它。 Any help would be greatly appreciated!任何帮助将不胜感激!

It seems you are dealing with a modal dialog window.看来您正在处理一个模态对话框 window。 When it is displayed to a user the code stops running and can be resumed only after it is closed.当它显示给用户时,代码停止运行,只有在关闭后才能恢复。 A possible solution is to develop an external utility (application) which can scan Outlook windows periodically and click buttons programmatically.一种可能的解决方案是开发一个外部实用程序(应用程序),它可以定期扫描 Outlook windows 并以编程方式单击按钮。 Microsoft Active Accessibility can help you with that. Microsoft Active Accessibility可以帮助您。 But it is not a trivial task.但这不是一项微不足道的任务。

The Outlook object model doesn't provide anything for that. Outlook object model 没有为此提供任何东西。 You will have to use Windows API to get the job done.您必须使用 Windows API 才能完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM