| | |
VB6 - Look up email address from outlook address book?
![]() |
•
•
Join Date: Jul 2007
Posts: 113
Reputation:
Solved Threads: 0
Hello everyone,
is there a posibility that I can look up email addresses from outlook email address book instead of accepting email address from an inputbox or hard-coding it?
See my codes below:
Thanks.
tgifgemini
is there a posibility that I can look up email addresses from outlook email address book instead of accepting email address from an inputbox or hard-coding it?
See my codes below:
Thanks.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
SENDEMAIL: Set OutlookApp = CreateObject("Outlook.Application") Set OutlookMail = OutlookApp.CreateItem(0) 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
tgifgemini
•
•
Join Date: Jun 2007
Posts: 166
Reputation:
Solved Threads: 9
•
•
•
•
Hello everyone,
is there a posibility that I can look up email addresses from outlook email address book instead of accepting email address from an inputbox or hard-coding it?
See my codes below:
Thanks.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
SENDEMAIL: Set OutlookApp = CreateObject("Outlook.Application") Set OutlookMail = OutlookApp.CreateItem(0) 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
tgifgemini
No means not directly and Yes means indirectly.
Why not directly ? Because it exposes the address book to hackers very easily.
How indirectly ? There is a Outlook Express API (OEAPI) developed by third parties which you can use it, not only in VB but also in host of other programming languages.
If you are a very advanced programmer you would be knowing it already or else while you approach to that category you will come across with it.
Be contended now and get back to me later.
Happy programming
regards
AV Manoharan
Hi tgif,
Add a Listbox to the form and
use this code:
In above code, change MyContacts to the name of ur Address Book.
Regards
Veena
Add a Listbox to the form and
use this code:
Option Explicit Dim ola As Outlook.AddressList Dim ole As Outlook.AddressEntry List1.Clear Private Sub address_book_Click() On Error Resume Next Set ola = Application.Session.AddressLists("MyContacts") For Each ole In ola.AddressEntries List1.AddItem ole Next Set ola = Nothing Set ole = Nothing End Sub
In above code, change MyContacts to the name of ur Address Book.
Regards
Veena
•
•
Join Date: Jun 2007
Posts: 166
Reputation:
Solved Threads: 9
•
•
•
•
Hi tgif,
Add a Listbox to the form and
use this code:
Option Explicit Dim ola As Outlook.AddressList Dim ole As Outlook.AddressEntry List1.Clear Private Sub address_book_Click() On Error Resume Next Set ola = Application.Session.AddressLists("MyContacts") For Each ole In ola.AddressEntries List1.AddItem ole Next Set ola = Nothing Set ole = Nothing End Sub
In above code, change MyContacts to the name of ur Address Book.
Regards
Veena
Hi tgif,
If u dont know the Address Book name, u can loop thru all the AddressBooks and List It,
Add a "ListView" Control to ur form and rename it as "lvw", Check this code:
REgards
Veena
If u dont know the Address Book name, u can loop thru all the AddressBooks and List It,
Add a "ListView" Control to ur form and rename it as "lvw", Check this code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub FillListView() Dim olApp As Outlook.Application Dim olNS As Outlook.NameSpace Dim olAL As Outlook.AddressList Dim olAE As Outlook.AddressEntry Dim olMail As Outlook.MailItem Set olApp = New Outlook.Application Set olNS = olApp.GetNamespace("MAPI") For Each olAL In olNS.AddressLists For Each olAE In olAL.AddressEntries lvw.ListItems.Add , , olAE.Name lvw.ListItems(lvw.ListItems.Count).SubItems(1) = olAE.Address lvw.ListItems(lvw.ListItems.Count).SubItems(2) = olAE.ID lvw.ListItems(lvw.ListItems.Count).Tag = olAE.ID Next Next End Sub
REgards
Veena
•
•
Join Date: Jul 2007
Posts: 113
Reputation:
Solved Threads: 0
Good afternoon Veena,
I am getting Run-time error 424 - Object required on this line ==>:"lvw.ListItems.Add , , OutlookAddressEntry.Name"
See my code below:
Thanks
tgifgemini
I am getting Run-time error 424 - Object required on this line ==>:"lvw.ListItems.Add , , OutlookAddressEntry.Name"
See my code below:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Set OutlookApp = New Outlook.Application Set OutlookMailItem = OutlookApp.CreateItem(0) Set OutlookNSpace = OutlookApp.GetNamespace("MAPI") 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 Next Next EmailID = lvw.ListItems(lvw.ListItems.Count).SubItems(1) OutlookMailItem.To = EmailID OutlookMailItem.Subject = "Project Status" OutlookMailItem.Body = "This is VB email test" 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
Thanks
tgifgemini
Hi tgif,
Just remove the Listview, and add a MSFlexgrid, rename it as grd. check this code:
Regards
Veena
Just remove the Listview, and add a MSFlexgrid, rename it as grd. check this code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub FillListView() Dim olApp As Outlook.Application Dim olNS As Outlook.NameSpace Dim olAL As Outlook.AddressList Dim olAE As Outlook.AddressEntry Dim olMail As Outlook.MailItem Dim i As Long Grd.Rows=1 Grd.Cols=4 i=0 Set olApp = New Outlook.Application Set olNS = olApp.GetNamespace("MAPI") For Each olAL In olNS.AddressLists For Each olAE In olAL.AddressEntries i=i+1 Grd.rows=i+1 Grd.textMatrix(i,0)=olAE.Name Grd.textMatrix(i,1)=olAE.Address Grd.textMatrix(i,2)=olAE.ID Grd.textMatrix(i,3)=olAE.ID Next Next End Sub
Regards
Veena
Last edited by QVeen72; Jul 24th, 2007 at 3:25 am.
•
•
Join Date: Jul 2007
Posts: 113
Reputation:
Solved Threads: 0
Good morning Veena,
Your directives is getting me closer to my objective. I did as you said. Now, I am stepping thru the program and I can see the email address information being loaded into the flexgrid control. However at a point, I want to be able to select an email address from the flexgrid, place it in the "EmailID" variable which I will subsequently point to in the "OutlookMailItem.To = EmailID"
See all my code/setup below:
Your directives is getting me closer to my objective. I did as you said. Now, I am stepping thru the program and I can see the email address information being loaded into the flexgrid control. However at a point, I want to be able to select an email address from the flexgrid, place it in the "EmailID" variable which I will subsequently point to in the "OutlookMailItem.To = EmailID"
See all my code/setup below:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Flxgrd_Click() Dim OutlookApp As Outlook.Application Dim OutlookNameSpace As Outlook.NameSpace Dim OutlookAddressList As Outlook.AddressList Dim OutlookAddressEntry As Outlook.AddressEntry Dim OutlookMailItem As Outlook.MailItem Dim i As Long Dim EmailID As String Dim OutlookAttachment As Outlook.Attachment Dim MailAttach As String MailAttach = "C:\ProjectStatus.xls" Flxgrd.Rows = 1 Flxgrd.Cols = 4 i = 0 Set OutlookApp = New Outlook.Application Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI") For Each OutlookAddressList In OutlookNameSpace.AddressLists For Each OutlookAddressEntry In OutlookAddressList.AddressEntries i = i + 1 Flxgrd.Rows = i + 1 Flxgrd.TextMatrix(i, 0) = OutlookAddressEntry.Name Flxgrd.TextMatrix(i, 1) = OutlookAddressEntry.Address Flxgrd.TextMatrix(i, 2) = OutlookAddressEntry.ID Flxgrd.TextMatrix(i, 3) = OutlookAddressEntry.ID Next Next EmailID = "gift.xtian@nyct.com" SENDEMAIL: OutlookMailItem.To = EmailID OutlookMailItem.Subject = "Project Status" OutlookMailItem.Body = "This is VB email test" If Not IsMissing(MailAttach) Then Set OutlookAttachment = 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 Set OutlookNameSpace = Nothing Set OutlookAddressList = Nothing Set OutlookAddressEntry = Nothing Set OutlookAttachment = Nothing End Sub
•
•
Join Date: Jul 2007
Posts: 113
Reputation:
Solved Threads: 0
Re: VB6 Runtime Error: 380 Invalid property value (Accessing global email address fld
0
#10 Jul 25th, 2007
Hi Veena,
Sorry I've been going back and forth with this issue. But I was able to bring in the "ListView" control component and my code is executing up to a point where I get a "Runtime error - 380 - Invalid Property value" on these lines of codes:
Also, I want to be able to select my desired email address from the list.
Below is my entire code:
Thanks,
tgifgemini.
Sorry I've been going back and forth with this issue. But I was able to bring in the "ListView" control component and my code is executing up to a point where I get a "Runtime error - 380 - Invalid Property value" on these lines of codes:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Also, I want to be able to select my desired email address from the list.
Below is my entire code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim OutlookApp As Outlook.Application Dim OutlookNameSpace As Outlook.NameSpace Dim OutlookAddressList As Outlook.AddressList Dim OutlookAddressEntry As Outlook.AddressEntry Dim OutlookMailItem As Outlook.MailItem Dim i As Long Dim EmailID As String Dim OutlookAttachment As Outlook.Attachment Dim MailAttach As String MailAttach = "C:\ProjectStatus.xls" Set OutlookApp = New Outlook.Application Set OutlookMailItem = OutlookApp.CreateItem(olMailItem) Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI") For Each OutlookAddressList In OutlookNameSpace.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 Next Next EmailID = "????????????????????????" OutlookMailItem.To = EmailID OutlookMailItem.Subject = "Project Status" OutlookMailItem.Body = "This is VB email test" If Len(MailAttach) > 0 Then OutlookMailItem.Attachments.Add (MailAttach) End If 'OutlookMailItem.Display 'To display the email OutlookMailItem.Send 'To send the email End Sub
tgifgemini.
![]() |
Similar Threads
- VB 6.0 - Accepting value (email address)from Inputbox (Visual Basic 4 / 5 / 6)
- outlook 03 email address read as word; duplicate email (Windows Software)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: separating lines in vb6 using richtextbox
- Next Thread: where-like in vb6
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





