Hi, i recently bought "Office VBA Macros You Can Use Today". I am trying out the outlook macro that sends out emails with attachments when a reminder occurs.
This is the code.
Option Explicit
'****
Private Sub Application_Reminder(ByVal Item As Object)
Call SendFiles(Item)
End Sub
Private Sub SendFiles(objTask As TaskItem)
Dim objMail As Object
Dim msg As Object
Dim strCategoryName As String
Dim strFileName As String
Dim strContact
Dim i As Integer 'Counter
On Error GoTo ErrorHandler
strCategoryName = "Custom"
If Not objTask.Categories = strCategoryName Then Exit Sub
If Dir(objTask.Body) = "" Then Exit Sub
strFileName = Trim(objTask.Body)
Set objMail = Application.CreateItem(olMailItem)
With objMail
.Subject = objTask.Subject
.Attachments.Add strFileName
strContact = Split(objTask.ContactNames, ",")
If Not IsArray(strContact) Then
strContact = Split(objTask.ContactNames, ",")
End If
For i = 0 To UBound(strContact)
.Recipients.Add strContact(i)
Next i
.Send
End With
With objTask
.ReminderSet = False
.Close olSave
End With
ExitSub:
Exit Sub
ErrorHandler:
MsgBox Err.Number & "-" & Err.Description, _
vbOKOnly + vbExclamation, "Error"
GoTo ExitSub
End Sub
The code compiles with no errors; i've put the filename in the body of the reminder; i've changed and placed the task in the correct category called 'Custom' but when the reminder fires, nothing is sent out at all, with no errors as well.
I believe it's not sending because of the contacts part(in red font) of the code. i've also tried placing contacts in a 'Custom' category as well but that did not work.
The example shown in the book shows outlook 2003. im wondering if that makes a difference?
This is the code.
Option Explicit
'****
Private Sub Application_Reminder(ByVal Item As Object)
Call SendFiles(Item)
End Sub
Private Sub SendFiles(objTask As TaskItem)
Dim objMail As Object
Dim msg As Object
Dim strCategoryName As String
Dim strFileName As String
Dim strContact
Dim i As Integer 'Counter
On Error GoTo ErrorHandler
strCategoryName = "Custom"
If Not objTask.Categories = strCategoryName Then Exit Sub
If Dir(objTask.Body) = "" Then Exit Sub
strFileName = Trim(objTask.Body)
Set objMail = Application.CreateItem(olMailItem)
With objMail
.Subject = objTask.Subject
.Attachments.Add strFileName
strContact = Split(objTask.ContactNames, ",")
If Not IsArray(strContact) Then
strContact = Split(objTask.ContactNames, ",")
End If
For i = 0 To UBound(strContact)
.Recipients.Add strContact(i)
Next i
.Send
End With
With objTask
.ReminderSet = False
.Close olSave
End With
ExitSub:
Exit Sub
ErrorHandler:
MsgBox Err.Number & "-" & Err.Description, _
vbOKOnly + vbExclamation, "Error"
GoTo ExitSub
End Sub
The code compiles with no errors; i've put the filename in the body of the reminder; i've changed and placed the task in the correct category called 'Custom' but when the reminder fires, nothing is sent out at all, with no errors as well.
I believe it's not sending because of the contacts part(in red font) of the code. i've also tried placing contacts in a 'Custom' category as well but that did not work.
The example shown in the book shows outlook 2003. im wondering if that makes a difference?