populating worksheet with Outlook mail

  • Thread starter VG9uZXk
  • Start date Views 1,572
V

VG9uZXk

Hello. I want to populate a worksheet with my Outlook inbox content (all 2007

versions with Vista). I get erros on invalid params on olFolderInbox as

indicated in code below. (I sometimes get erros on creating the initial app

object, but not as often). BTW, I run this code from Excel, and I have

created ref to outlook library.

Sub getMail()

Dim ol As Outlook.Application

Dim ns As Namespace

Dim folder As MAPIFolder

Dim ws As Worksheet

Dim i As Integer

Set ol = CreateObject("Outlook.Application")

Set ns = ol.GetNamespace("MAPI")

ns.Logon

'errors about parameter value not valid on next line:

Set folder = ns.GetDefaultFolder(olFolderIndox)

Set ws = Worksheets("Receive Mail")

For i = 1 To folder.Items.Count

With folder.Items(i)

ws.[A1].Offset(i, 0) = .SenderName

ws.[A1].Offset(i, 1) = .SenderEmailAddress

ws.[A1].Offset(i, 2) = .Subject

ws.[A1].Offset(i, 3) = .Size

ws.[A1].Offset(i, 4) = .ReceivedTime

ws.[A1].Offset(i, 5) = .Left(.Body, 100)

End With

Next i

ns.Logoff

Set ol = Nothing

End Sub
 
S

Sue Mosher [MVP]

Look at that problem statement again to find the typo. It doesn't say

olFolderInbox at all.

Sue Mosher

"Toney" <Toney> wrote in message

news:BFEF6362-373E-46B1-9FAD-C25913FDDDA1@microsoft.com...
> Hello. I want to populate a worksheet with my Outlook inbox content (all
> 2007
> versions with Vista). I get erros on invalid params on olFolderInbox as
> indicated in code below. (I sometimes get erros on creating the initial
> app
> object, but not as often). BTW, I run this code from Excel, and I have
> created ref to outlook library.

> Sub getMail()

> Dim ol As Outlook.Application
> Dim ns As Namespace
> Dim folder As MAPIFolder
> Dim ws As Worksheet

> Dim i As Integer

> Set ol = CreateObject("Outlook.Application")
> Set ns = ol.GetNamespace("MAPI")
> ns.Logon

> 'errors about parameter value not valid on next line:

> Set folder = ns.GetDefaultFolder(olFolderIndox)

> Set ws = Worksheets("Receive Mail")

> For i = 1 To folder.Items.Count
> With folder.Items(i)

> ws.[A1].Offset(i, 0) = .SenderName
> ws.[A1].Offset(i, 1) = .SenderEmailAddress
> ws.[A1].Offset(i, 2) = .Subject
> ws.[A1].Offset(i, 3) = .Size
> ws.[A1].Offset(i, 4) = .ReceivedTime
> ws.[A1].Offset(i, 5) = .Left(.Body, 100)

> End With
> Next i

> ns.Logoff
> Set ol = Nothing

> End Sub

>
 
V

VG9uZXk

Dang. This is why I should type everyting in lower cases, to help me find

these errors. This time, I probably didn't do this.

Thanks much. My code words now.

Toney

"Sue Mosher [MVP]" wrote:


> Look at that problem statement again to find the typo. It doesn't say
> olFolderInbox at all.

> > Sue Mosher
> > >

> "Toney" <Toney> wrote in message
> news:BFEF6362-373E-46B1-9FAD-C25913FDDDA1@microsoft.com...
> > Hello. I want to populate a worksheet with my Outlook inbox content (all
> > 2007
> > versions with Vista). I get erros on invalid params on olFolderInbox as
> > indicated in code below. (I sometimes get erros on creating the initial
> > app
> > object, but not as often). BTW, I run this code from Excel, and I have
> > created ref to outlook library.
> > Sub getMail()
> > Dim ol As Outlook.Application
> > Dim ns As Namespace
> > Dim folder As MAPIFolder
> > Dim ws As Worksheet
> > Dim i As Integer
> > Set ol = CreateObject("Outlook.Application")
> > Set ns = ol.GetNamespace("MAPI")
> > ns.Logon
> > 'errors about parameter value not valid on next line:
> > Set folder = ns.GetDefaultFolder(olFolderIndox)
> > Set ws = Worksheets("Receive Mail")
> > For i = 1 To folder.Items.Count
> > With folder.Items(i)
> > ws.[A1].Offset(i, 0) = .SenderName
> > ws.[A1].Offset(i, 1) = .SenderEmailAddress
> > ws.[A1].Offset(i, 2) = .Subject
> > ws.[A1].Offset(i, 3) = .Size
> > ws.[A1].Offset(i, 4) = .ReceivedTime
> > ws.[A1].Offset(i, 5) = .Left(.Body, 100)
> > End With
> > Next i
> > ns.Logoff
> > Set ol = Nothing
> > End Sub
> >


>
 

Top