944,149 Members | Top Members by Rank

Ad:
Jul 20th, 2007
0

VB6 - Email attachment not working

Expand Post »
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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Set OutlookApp = CreateObject("Outlook.Application")
  2. Set OutlookMail = OutlookApp.CreateItem(0)
  3. Set NSpace = OutlookApp.GetNamespace("MAPI")
  4. Set OutlookContacts = NSpace.GetDefaultFolder _(olFolderContacts).Items
  5.  
  6. MailAttach = "C:\ProjectStatus.xls" <-- This spreadsheet resides in my hard drive.
  7.  
  8. OutlookMail.To = EmailID
  9. OutlookMail.Subject = "Project Status"
  10. OutlookMail.Body = "This is VB email test"
  11.  
  12. If Len(MailAttach) = 0 Then
  13. OutlookMail.Attachments.Add MailAttach '"C:\ProjectStatus.xls"
  14. End If
  15.  
  16. 'OutlookMail.Display 'To display the email
  17. OutlookMail.Send 'To send the email
  18.  
  19. Set OutlookApp = Nothing
  20. Set OutlookMail = Nothing

Any assistance will be appreciated.
tgifgemini
Similar Threads
Reputation Points: 22
Solved Threads: 0
Junior Poster
tgifgemini is offline Offline
113 posts
since Jul 2007
Jul 21st, 2007
0

Re: VB6 - Email attachment not working

Hi,

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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim OAttach As Outlook.Attachment
  2. If Not IsMissing(MailAttach) Then
  3. Set OAttach = OutLookMail.Attachments.Add(MailAttach)
  4. End If


Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Jul 23rd, 2007
0

Re: VB6 - Email attachment not working

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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. lvw.ListItems.Add , , OutlookAddressEntry.Name
Thanks again,
tgifgemini.
Reputation Points: 22
Solved Threads: 0
Junior Poster
tgifgemini is offline Offline
113 posts
since Jul 2007
Jul 23rd, 2007
0

Re: VB6 - Runtime error 424 - Object required (Outlook email set up)

In my perception, I have dimensioned the object below, but have not set it; To what should I set it?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim OutlookAddressEntry As Outlook.AddressEntry
  2.  
  3. Set OutlookAddressEntry = ????????????? <== This maybe my problem

You can see all the previous code you gave me.
tgifgemini.
Reputation Points: 22
Solved Threads: 0
Junior Poster
tgifgemini is offline Offline
113 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: referential integrity in access DB
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Optimizing text file writing in VB 6.0





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC