Hello everyone,
I am having a problem completing my outlook email setup through VB.
I am gettin Run-time error 424 - Object required:
Actually someone got me to this point, but I'm bumming out on this line:
"lvw.ListItems.Add , , OutlookAddressEntry.Name" - basically all the lines that have the prefix "lvw." because I don't know where that prefix is coming from.
Also, the "OutlookAddressEntry" is not set.
Please help.

Dim OutlookApp As Object
Dim OutlookMailItem As Outlook.MailItem
Dim OutlookAddressList As Outlook.AddressList
Dim OutlookAddressEntry As Outlook.AddressEntry
Dim MailAttach As String
Dim OutlookNSpace As Outlook.NameSpace
Dim OutlookAttach As Outlook.Attachment

MailAttach = "C:\ProjectStatus.xls"
 'Send Email using outlook application
 'Note: outlook must be installed on your PC for this module to work:
 Set OutlookApp = New Outlook.Application
 Set OutlookMailItem = OutlookApp.CreateItem(0)
 Set OutlookNSpace = OutlookApp.GetNamespace("MAPI")
'Get email address from global email address folder
For Each OutlookAddressList In OutlookNSpace.AddressLists
    For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
        lvw.ListItems.Add , , OutlookAddressEntry.Name
        lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address
        lvw.ListItems(lvw.ListItems.Count).SubItems(2) = OutlookAddressEntry.ID
        lvw.ListItems(lvw.ListItems.Count).Tag = OutlookAddressEntry.ID

 EmailID = lvw.ListItems(lvw.ListItems.Count).SubItems(1)

 If Trim(EmailID) <> "" And Trim(EmailID) Like "*@*.*" Or Trim(EmailID) Like "*@*.com" Then
    MsgBox ("You have entered an invalid email address"), vbCritical, "Email Address Error!"
    Exit Sub
 End If

 OutlookMailItem.To = EmailID
 OutlookMailItem.Subject = "Project Status"
 OutlookMailItem.Body = "This is VB email test"
 If Not IsMissing(MailAttach) Then
  Set OutlookAttach = OutlookMailItem.Attachments.Add(MailAttach)
 End If
 'If Len(MailAttach) > 0 Then
 '   OutlookMailItem.Attachments.Add "C:\ProjectStatus.xls", olByValue, 1, "ProjectStatus"
 'End If
 'OutlookMailItem.Display      'To display the email
 OutlookMailItem.Send         'To send the email
 Set OutlookApp = Nothing
 Set OutlookMailItem = Nothing


do you have a listview named lvw?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.