我已經寫在Outlook中宏和Excel VBA中,描述是: 1.代碼在Outlook開放的Excel文件,如果電子郵件主題行匹配:錯誤雖然通過Outlook從Excel發送電子郵件VBA
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
'// Subject line here
If InStr(Item.Subject, "Run Dashboard") Then
Call openExcel
End If
End If
End Sub
一旦Excel打開並且儀表板已經運行,那麼電子郵件必須通過Excel發送。
VBA和代碼:
Dim outapp As Object
Dim nmail As Object
Set outapp = CreateObject("Outlook.Application")
Set nmail = outapp.CreateItem(0)
With nmail
.To = "[email protected]"
.cc = ""
.bcc = ""
.Subject = flname
.htmlbody = RangetoHTML(Range("A1:" & Split(Cells(, lastcol1).Address, "$")(1) & lastrow1))
.attachments.Add ActiveWorkbook.FullName
.display
End With
On Error GoTo 0
Set nmail = Nothing
Set outapp = Nothing
現在我面對錯誤的Set outapp = CreateObject("Outlook.Application")
如果我打開Excel通過Outlook電子郵件文件中第1點中提到,如果我在正常方式打開文件時,此錯誤是隻顯示即沒有Outlook幫助,則代碼正在成功運行。
請幫助相同。
在此先感謝
,而不是'昏暗outapp作爲object'你有沒有試着用'昏暗outapp爲outlook.Application'和'暗淡nmail作爲outlook.MailItem'同時檢查'微軟Outlook'參考是否包含 – Tom
感謝這個工作:) – Dharmendra
現在越來越錯誤「設置nmail = outapp.CreateItem(olMailItem)」在excel vba – Dharmendra