Extract Data from Specific Folder - Outlook macro

T

tysone

I posted this in a similar group, but that group looks all but dead. Not that this one is pumping full of life, but I'm giving it a go. So please forgive me for the double-esk post

======================
So I think I'm 90% of where I want to be, and I'm hoping someone can help me.

The code below works great, but it has two problems for what I need. I do not want it pulled from "CurrentFolder," I want it to always pull from the inbox. And the second part of my problem its not my main inbox, it's on a second account I have linked in my outlook (for example sake call it "(e-mail address removed)").

Help would be greatly appreciated,



Sub Extract()

On Error Resume Next
Set myOlApp = Outlook.Application
Set myNameSpace = myOlApp.GetNamespace("mapi")
'==this is my issue, I do not want it coming from currentfolder==
Set myfolder = myOlApp.ActiveExplorer.CurrentFolder
Set xlobj = CreateObject("excel.application.14")
xlobj.Visible = True
xlobj.workbooks.Add
xlobj.Range("A" & 1).Value = "Recieved time"
xlobj.Range("B" & 1).Value = "Sender"
xlobj.Range("C" & 1).Value = "Subject"
xlobj.Range("D" & 1).Value = "Size"
For i = 1 To myfolder.Items.Count
Set myitem = myfolder.Items(i)
msgtext = myitem.Body

xlobj.Range("A" & i + 1).Value = myitem.ReceivedTime
xlobj.Range("B" & i + 1).Value = myitem.Sender
xlobj.Range("C" & i + 1).Value = myitem.Subject
xlobj.Range("D" & i + 1).Value = myitem.Size

Next
End Sub
 
A

Auric__

tysone said:
I posted this in a similar group, but that group looks all but dead.
Not that this one is pumping full of life, but I'm giving it a go. So
please forgive me for the double-esk post

=====================So I think I'm 90% of where I want to be, and I'm
hoping someone can help me.

The code below works great, but it has two problems for what I need. I
do not want it pulled from "CurrentFolder," I want it to always pull
from the inbox. And the second part of my problem its not my main
inbox, it's on a second account I have linked in my outlook (for example
sake call it "(e-mail address removed)").

Help would be greatly appreciated,

I don't program for Outlook -- in fact, I don't even install it -- but
this comes from poking around MSDN a bit.

- Folder Object:
http://msdn.microsoft.com/en-us/library/office/bb176362.aspx
- Folders Object:
http://msdn.microsoft.com/en-us/library/office/bb147608.aspx
- OlDefaultFolders Enumeration:
http://msdn.microsoft.com/en-us/library/office/bb208072.aspx
Sub Extract()

On Error Resume Next
Set myOlApp = Outlook.Application
Set myNameSpace = myOlApp.GetNamespace("mapi")
'==this is my issue, I do not want it coming from currentfolder==
Set myfolder = myOlApp.ActiveExplorer.CurrentFolder

Remove "myNameSpace" entirely, and replace the above line with this:

Set myfolder = _
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

This is just a guess; I don't know *ANYTHING* about Outlook. *STEP*
through this code (F8) to see if it has any chance of working.
Set xlobj = CreateObject("excel.application.14")
xlobj.Visible = True
xlobj.workbooks.Add
xlobj.Range("A" & 1).Value = "Recieved time"
xlobj.Range("B" & 1).Value = "Sender"
xlobj.Range("C" & 1).Value = "Subject"
xlobj.Range("D" & 1).Value = "Size"
For i = 1 To myfolder.Items.Count
Set myitem = myfolder.Items(i)
msgtext = myitem.Body

xlobj.Range("A" & i + 1).Value = myitem.ReceivedTime
xlobj.Range("B" & i + 1).Value = myitem.Sender
xlobj.Range("C" & i + 1).Value = myitem.Subject
xlobj.Range("D" & i + 1).Value = myitem.Size

Next
End Sub

Let me know if this works; I'm curious.
 
T

tysone

That did it! Thank you. Now for your next trick, can you make it pull from my other mail box's inbox too?

Regards,

T
 
T

tysone

Figured it out.

Set myfolder = Application.GetNamespace("MAPI").Folders("(e-mail address removed)").Folders("Inbox")

Thanks for the help!
 
A

Auric__

tysone said:
Figured it out.

Set myfolder = Application.GetNamespace("MAPI").Folders("bob123
@hotmail.com").Folders("Inbox")

Thanks for the help!

Glad you figured it out, because I don't know that I could have. As I said, I
don't program Outlook.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top