Error in macro - please help

G

Guest

Hi,

I am using the macro below to send an e-mail from excel (through outlook).
When there is no attachment to the e-mail (take that command out) it works
fine. However, when you try and attach a file it comes up it comes up with
Run-time error 438. Object doesn't support this property or method.
Here is the macro - I would be grateful for any assistance.

Sub Mail_workbook_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strto As String

For Each cell In ThisWorkbook.Sheets("E-mail Contacts") _
.Columns("i").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "*@*" Then
strto = strto & cell.Value & ";"
End If
Next
strto = Left(strto, Len(strto) - 1)

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = ""
.CC = ""
.BCC = strto
.Subject = ""
.Body = ""
.Attachment.Add ("")
.Send 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
A

Ardus Petus

Use Attachments (with an "s")
You also forgot to Quit Outlook:

HTH
--
AP

'--------------
Sub Mail_workbook_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strto As String

For Each cell In ThisWorkbook.Sheets("E-mail Contacts") _
.Columns("i").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "*@*" Then
strto = strto & cell.Value & ";"
End If
Next
strto = Left(strto, Len(strto) - 1)

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = strto
.CC = ""
.BCC = ""
.Subject = "test mail"
.Body = "See attachment"
.Attachments.Add ("c:\boot.ini")
.Send 'or use .Display
End With
OutApp.Quit
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
'------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top