954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB6 - Email attachment not working

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

tgifgemini
Junior Poster
113 posts since Jul 2007
Reputation Points: 22
Solved Threads: 0
 

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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

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.

tgifgemini
Junior Poster
113 posts since Jul 2007
Reputation Points: 22
Solved Threads: 0
 

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.

tgifgemini
Junior Poster
113 posts since Jul 2007
Reputation Points: 22
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You