VB6 - Email attachment not working
Hi,
I wrote this program to send email through VB. The email is working okay but the attachment I need to attach to the email is not being attached.

See my codes below:

Set OutlookApp = CreateObject("Outlook.Application")
 Set OutlookMail = OutlookApp.CreateItem(0)
 Set NSpace = OutlookApp.GetNamespace("MAPI")
 Set OutlookContacts = NSpace.GetDefaultFolder  _(olFolderContacts).Items

MailAttach = "C:\ProjectStatus.xls"  <-- This spreadsheet resides in my hard drive.
  
 OutlookMail.To = EmailID
 OutlookMail.Subject = "Project Status"
 OutlookMail.Body = "This is VB email test"
 
 If Len(MailAttach) = 0 Then
    OutlookMail.Attachments.Add MailAttach  '"C:\ProjectStatus.xls"
 End If
 
 'OutlookMail.Display      'To display the email
 OutlookMail.Send         'To send the email
    
 Set OutlookApp = Nothing
 Set OutlookMail = Nothing

Any assistance will be appreciated.
tgifgemini

Hi,

along with the above code, Create a seperate Attacmnet object, check this code:

Dim OAttach As Outlook.Attachment
If Not IsMissing(MailAttach) Then
  Set OAttach = OutLookMail.Attachments.Add(MailAttach)
End If

Regards
Veena

Thanks for your expertise. My attachment is working now. However, I have one minor problem. See my follow-up post regarding RT Error: 424 object required.
My code bummed out on this line:

lvw.ListItems.Add , , OutlookAddressEntry.Name

Thanks again,
tgifgemini.

In my perception, I have dimensioned the object below, but have not set it; To what should I set it?

Dim OutlookAddressEntry As Outlook.AddressEntry

Set OutlookAddressEntry = ????????????? <== This maybe my problem

You can see all the previous code you gave me.
tgifgemini.

This article has been dead for over six months. Start a new discussion instead.