Results 1 to 8 of 8

Thread: Outlook Contacts

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Posts
    305

    Outlook Contacts

    Hi,can some one show me an example of extracting the outlook contacts to a listbox?,would be good just with pure api so no dlls etc thanks

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Outlook Contacts

    API's are using dll's. Try using VBScript in VB. Google this for some excellent code "VBScript Outlook" without the quotes.

  3. #3
    Junior Member
    Join Date
    Mar 2005
    Posts
    18

    Re: Outlook Contacts

    Code:
    Private Sub Command1_Click()
      Dim o As New Outlook.Application, ns As Outlook.Namespace
      Dim fldr As Outlook.MAPIFolder, ctcItems As Outlook.Items
      Dim j As Integer
      Set ns = o.GetNamespace("MAPI")
      Set fldr = ns.GetDefaultFolder(olFolderContacts)
      Set ctcItems = fldr.Items
      For j = 1 To ctcItems.Count
         On Error Resume Next ' in case you encounter a distribution list 
         List1.AddItem ctcItems.Item(j).FullName
      Next j
    End Sub
    Hope this helps
    Last edited by Xiarcel; Jun 10th, 2005 at 10:49 PM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Posts
    305

    Re: Outlook Contacts

    what refrences do i need?

  5. #5
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Outlook Contacts

    Quote Originally Posted by Mr_Zer0
    what refrences do i need?
    Microsoft Outlook xxx Object Library

    Where xxx is the version nmber of your Outlook package

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  6. #6
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Outlook Contacts

    You don't have to use references when you use VBScript in VB just to let you know.
    But his code requires it.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook Contacts

    There are a couple of variations of what you could do.

    You could use VB Script behind a Outlook Form to do this.
    You could use VB6 to automate it like posted.
    You could use early binding like posted.
    You could use late binding so it will work without any references (vb script or vb6).
    '...
    '...
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Junior Member
    Join Date
    Mar 2005
    Posts
    18

    Re: Outlook Contacts

    If you don't want to add references
    Code:
    Private Sub Command1_Click()
      Dim o As Object, ns As Object
      Dim fldr As Object, ctcItems As Object
      Dim j As Integer
      Dim ctc As Object
      Set o = CreateObject("Outlook.Application")
      Set ns = o.GetNamespace("MAPI")
      Set fldr = ns.GetDefaultFolder(10)
      Set ctcItems = fldr.Items
      For j = 1 To ctcItems.Count
         On Error Resume Next
         List1.AddItem ctcItems.Item(j).FullName
      Next j
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width