Discussion:
Extract Data from Specific Folder - Outlook macro
(too old to reply)
t***@gmail.com
2013-06-08 04:38:31 UTC
Permalink
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 "***@hotmail.com").

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
Auric__
2013-06-08 05:10:25 UTC
Permalink
Post by t***@gmail.com
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
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
Post by t***@gmail.com
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.
Post by t***@gmail.com
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.
--
Students have social license to do bugger all
for a few years prior to working for a living.
t***@gmail.com
2013-06-10 14:42:41 UTC
Permalink
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
Post by t***@gmail.com
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.
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
t***@gmail.com
2013-06-10 14:56:36 UTC
Permalink
Figured it out.

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

Thanks for the help!
Post by t***@gmail.com
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
Post by t***@gmail.com
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.
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
Auric__
2013-06-11 02:24:04 UTC
Permalink
Post by t***@gmail.com
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.
--
- Ah, protection. Like a gun.
- NO--
- YES, sometimes.
Loading...