2
由於this problem不可解析,因此我正在探索一個用於自動生成InfoPath電子郵件的不同選項。如何在對象接管時使用CreateObject並傳遞用戶輸入?
下面的代碼工作,除了一旦我使用.Submit
它會提示我使用輸入 - 基本上InfoPath窗口要求我在對話框中點擊「發送」。
我希望有一種方法可以基本上做下面的代碼在僞代碼中做的事情。問題是當.Submit
被調用時(documentation here - 看起來好像沒有任何標誌可以通過/設置忽略這個),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 = "[email protected]"
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