populating worksheet with Outlook mail

  • Thread starter Thread starter VG9uZXk
  • Start date Start date
Status
Not open for further replies.
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
 
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

>
 
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
> >


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Outlook Reminders not populating for certain events Using Outlook 2
D populating listbox on custom form from Access Outlook VBA and Custom Forms 7
T populating multiple calendars without invites Using Outlook 1
microsvc Populating everyone's calendar with campus events Exchange Server Administration 1
T Populating listbox with MS Access table Using Outlook 2
S Custom field not populating in Custom View or Mail Merge Exchange Server Administration 2
B Populating Additional Outlook Column with Date \ Time Using Outlook 0
R My email merge/business contact manager fields are not populating BCM (Business Contact Manager) 1
T populating fields with information from the address book Outlook VBA and Custom Forms 5
M BCM History 'From' field not populating BCM (Business Contact Manager) 2
O Worksheet doesn't show on jumplist Using Outlook 1
L Open an Exel Macro Enabled Worksheet Using Outlook 4
kburrows Outlook Classic - JPG files are corrupted when opened or saved Using Outlook 0
F Sync Outlook Calendar Using Outlook 0
G Change default font size in sticky notes - Outlook Desktop 2021 Using Outlook 2
C VBA in "New Outlook?" Using Outlook 0
D New Outlook with Business Basic Plans Using Outlook 0
D Outlook 2021 not working with Outlook 2003 installed Using Outlook 5
D Outlook 2003 stopped working - get they dialog box asking for username & Password Using Outlook 2
T Outlook 2021 hangs in close on taskbar occasionally Using Outlook 1
M Duplicate removal feature in Outlook 2021 is faulty Using Outlook 2
D.Moore Outlook COM addins source folder Using Outlook 11
P Removing Outlook 365 Account from Send/Receive Using Outlook 3
kburrows Outlook Automatically Merging Contacts Using Outlook 1
A Outlook 2016 Outlook 2016 vs. New Outlook Using Outlook 4
D Outlook Desktop App Email Software Using Outlook 0
efire9207 VBA Outlook Contacts Outlook VBA and Custom Forms 6
M Outlook not logging in to server Using Outlook 0
J Outlook macro to run before email is being send Outlook VBA and Custom Forms 0
R Outlook 2021 change view Using Outlook 2
K Outlook font corrupted in some point sizes, resets on close/open Using Outlook 2
J Is the Windows Outlook Tasks module really going to be gone? Using Outlook 6
F Outlook 2010 and Hotmail Using Outlook 1
A Outlook 2021 needs 'enter' for people search Using Outlook 2
HarvMan Outlook 365 Inbox Font Using Outlook 8
Retired Geek Outlook on MAC delete duplicate Sent emails Using Outlook 0
S New Outlook - IMAP ISSUES and support for addins? Using Outlook 1
C outlook.com fonts Using Outlook 2
mickymakz Common challenges organizations face when integrating SharePoint and Outlook? Exchange Server Administration 0
R Outlook with several IMAP accounts generating folders with 1111 suffix Using Outlook 0
D Send email from Outlook Alias using Mac? Using Outlook 0
G Reply a selected message and remove blank space before signature Outlook 365 version 2406 64BIT Outlook VBA and Custom Forms 2
G Reply a selected message and remove blank space before signature Outlook 365 version 2406 64BIT Outlook VBA and Custom Forms 0
kburrows "New" Outlook Desktop App Mailbox Size Using Outlook 4
N Best way to sync calendar and contacts between Outlook 365 and Outlook on iPhone Using Outlook 4
H Macro to Delete Duplicate items in Outlook calendar where title is the same and date is the same Outlook VBA and Custom Forms 0
Y The New Outlook - Q's & Thoughts Using Outlook 28
M Start Outlook 365 at unified inbox Using Outlook 2
B Requesting VBA code to make Outlook prompt for confirmation when deleting a task? Outlook VBA and Custom Forms 4
T In-line reply style in Outlook II Outlook VBA and Custom Forms 1

Similar threads

Back
Top