I know I suggest this for everything but... SendKeys? This would close the window.
{
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.SendKeys("%fx")
}
The sendkeys method works on the active window; I would assume that by switching to outlook as the active window the code would continue to work in Outlook.
You could submit the form using this simple code instead of your version... what this will do is open a new message in InfoPath to the specified recipient. You could then add a further line to send it automatically.
var oEnvelope = Application.ActiveWindow.MailEnvelope;
oEnvelope.Subject = "yoursubjecthere";
oEnvelope.To = "[email protected]";
oEnvelope.Visible = true;
Then you could use SendKeys:
var WshShell = new ActiveXObject("Wscript");
WshShell.SendKeys("%s")
The overall code would appear as follows:
{ var oEnvelope = Application.ActiveWindow.MailEnvelope; oEnvelope.Subject = "yoursubjecthere"; oEnvelope.To = "[email protected]"; oEnvelope.Visible = true; var WshShell = new ActiveXObject("WScript.Shell"); WshShell.SendKeys("%s") }
Can I ask why they are asked to submit twice?