Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extract Data from Specific Folder - Outlook macro

53 views
Skip to first unread message

tys...@gmail.com

unread,
Jun 8, 2013, 12:38:31 AM6/8/13
to
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 "bob...@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__

unread,
Jun 8, 2013, 1:10:25 AM6/8/13
to
tysone wrote:

> 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 "bob...@hotmail.com").
>
> 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.

--
Students have social license to do bugger all
for a few years prior to working for a living.

tys...@gmail.com

unread,
Jun 10, 2013, 10:42:41 AM6/10/13
to
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

tys...@gmail.com

unread,
Jun 10, 2013, 10:56:36 AM6/10/13
to
Figured it out.

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

Thanks for the help!

Auric__

unread,
Jun 10, 2013, 10:24:04 PM6/10/13
to
tysone wrote:

> 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.
0 new messages