asked on
Sub Run Function()
On Error Resume Next
Dim OutApp As Object
Dim OutMail As Object
Dim objNsp As Object
Dim colSyc As Object
Dim objSyc As Object
Dim i As Integer
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set objNsp = OutApp.Application.GetNamespace("MAPI") 'CORRECTION to Refer to the OutLook Application correctly
Set colSyc = objNsp.SyncObjects
On Error Resume Next
With OutMail
.To = "whatever@whatever.com"
.Subject = "Vetting Report - " & TBFileName.Text
.Body = "For Your Information .."
.Attachments.Add BFld1 & TBFileName.Text
.Send ' to send in background
' .Display ' to open a mail window with a normal 'SEND' icon available
End With
For i = 1 To colSyc.Count
Set objSyc = colSyc.Item(i)
objSyc.Start
Next
On Error GoTo 0
OutApp.Quit
Set OutMail = Nothing
Set objNsp = Nothing
Set colSyc = Nothing
Set objSyc = Nothing
Set OutApp = Nothing
aa:
End Sub