因为这个问题似乎无法解决,所以我正在探索一个不同的选项来自动生成 InfoPath 电子邮件。
下面的代码有效,但一旦我使用.Submit
它会提示我使用输入 - 基本上 InfoPath 窗口要求我在对话框上点击“发送”。
我希望有一种方法可以基本上完成下面的代码在伪代码中所做的事情。问题是什么时候.Submit
被调用(这里的文档- 看起来没有任何标志我可以传递/设置来忽略它),VBA 等待按键继续(所以SendKeys
不像下面那样工作,至少做Alt+S)。
有关出现的确认示例,请参见下图:
我想抑制这种情况(即使我必须更改创建 InfoPath 电子邮件的方式)或者能够伪造“发送”按键。
Private Sub GenerateInfoPathEmail()
Dim mFilePath As String
Dim oApp As Object
Dim objEmailAdapter As EmailAdapterObject
mFilePath = "A:\tmp\testform.xsn"
Set oApp = CreateObject("InfoPath.Application")
oApp.XDocuments.NewFromSolution (mFilePath)
'infopath form has a connection called "email"
Set objEmailAdapter = oApp.XDocuments(0).DataAdapters("email")
objEmailAdapter.To = "myEmail@myDomain.com"
objEmailAdapter.CC = ""
objEmailAdapter.Intro = "intro"
objEmailAdapter.Subject = "subject"
objEmailAdapter.AttachmentType = 1 'xdXmlXns
objEmailAdapter.AttachmentFileName = mFilePath
'I want to be able to pass through
'the silly user input here to basically
'hit "send" (alt+s for keyboard shortcut)
objEmailAdapter.Submit
SendKeys ("%s") ' This obviously won't work because the code waits for user input
End Sub