Hi guys, I am trying to use the below codes to create outlook emails but seems doesn't work.
The emails I want to create don't contain any attachment, but these codes I copied from somewhere else were seems designed for emails with attachments. So if I don't have any files to attach, how can I amend these codes to make them work?
Currently I will get "Type mismatch" error when run these codes, as the attachment cells are empty.
thanks heaps guys!
------>error
Dim objOutlook As Outlook.Application
Dim objMail As MailItem
Set objOutlook = New Outlook.Application
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail
.To = Recipient
.CC = Recipientcc
.Subject = Subj
.Body = Body
Dim files As Variant
files = Split(Info_Arr(i, 5), ",")
For Each file In files
.Attachments.Add file
Next
.Save
End With
Set objMail = Nothing
Set objOutlook = Nothing
End Sub
[/CODE]
The emails I want to create don't contain any attachment, but these codes I copied from somewhere else were seems designed for emails with attachments. So if I don't have any files to attach, how can I amend these codes to make them work?
Currently I will get "Type mismatch" error when run these codes, as the attachment cells are empty.
thanks heaps guys!
Code:
Dim Info_Arr As Variant
Sub Send_Email_Macro()
Dim n%
Info_Arr = Sheet1.UsedRange
n = UBound(Info_Arr)
For i = 2 To n
Call Send_Email_By_Outlook(i)
Next i
End Sub
Sub Send_Email_By_Outlook(ByVal i As Integer)
Recipient = Info_Arr(i, 1)
Recipientcc = Info_Arr(i, 2)
Subj = Info_Arr(i, 3)
Body = Info_Arr(i, 4)
file = Info_Arr(i, 5)
If Len(Dir(file)) = 0 Then file = "" [CODE]
Dim objOutlook As Outlook.Application
Dim objMail As MailItem
Set objOutlook = New Outlook.Application
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail
.To = Recipient
.CC = Recipientcc
.Subject = Subj
.Body = Body
Dim files As Variant
files = Split(Info_Arr(i, 5), ",")
For Each file In files
.Attachments.Add file
Next
.Save
End With
Set objMail = Nothing
Set objOutlook = Nothing
End Sub
[/CODE]