Gather email address from outlook

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,291
Office Version
  1. 365
Platform
  1. Windows
I have found the following code on Dicks-Clicks website and I plan to change it so I can extract all email addresses in my send box.

However just running the code as is fails.

Can anyone suggest anything?

It fails on the first line
user-defined type not defined

Code:
Sub GetFromInbox()

    Dim olApp As Outlook.Application  <- Fails here
    Dim olNs As NameSpace
    Dim Fldr As MAPIFolder
    Dim olMail As Variant
    Dim i As Integer

    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
    i = 1

    For Each olMail In Fldr.Items
        If InStr(olMail.Body, "ozark") > 0 Or _
            InStr(olMail.Subject, "ozark") > 0 Then

            ActiveSheet.Cells(i, 1).Value = olMail.ReceivedTime
            i = i + 1
        End If
    Next olMail

    Set Fldr = Nothing
    Set olNs = Nothing
    Set olApp = Nothing

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
In the VBE, Tools > References and make sure that Microsoft Outlook is ticked.
 
Upvote 0
It was ticked - But it was 9.0

I unticked it and it became 11.0.

Reticked and now it works.

recently upgraded from outlook 2000 to 2003.
 
Upvote 0
how can I find a list of the properties associated with olmail?

Currently looking for ".from"

but might need others later.
 
Upvote 0
Got it thanks

Declared as .mailitem and then viewed in the locals window.
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top