Open a subfolder in a shared mail box.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I figured out how to export data from my emails but only from my inbox. I
want to open a shared mail box, subfolder.

I looked at several different options but can't figure out. I need a point
in the right direction so I can figure it out for myself.

I should point out that I'm a beginner.

Thank you in advance.

Shawn
 
If the mailbox is opened as part of your Outlook profile and happens to be
named "Mailbox - Casey Slovak" (my dog) then the code would look like this:

Dim oNS As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim oTarget As Outlook.MAPIFolder

Set oNS = Application.GetNameSpace("MAPI")

For Each oFolder In oNS.Folders
If oFolder.Name = "Mailbox - Casey Slovak" Then
Set oTarget = oFolder.Folders.Item("Inbox").Folders.Item("Folder of
Interest")
End If
Next

If Not(oTarget Is Nothing) Then
'got the right folder
End If
 
Ok I couldn't get it to work, I think it was the file name, so I changed it,
ran it and nothing happened. Then I realized I didn't tell it to do anything
so I put the txt code in and it didn't work.

I've got the concept but not the tools down.

Can you fix please?


Thanks

Sub OpenFolders()
Dim oNS As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim oTarget As Outlook.MAPIFolder

Set oNS = Application.GetNamespace("MAPI")

For Each oFolder In oNS.Folders
If oFolder.Name = "Mailbox - TheUgly_Data" Then
Set oTarget = oFolder.Folders.Item("Inbox").Folders.Item("Mailbox -
TheUgly_Data")
End If
Next

If Not (oTarget Is Nothing) Then
'got the right folder
End If
Dim Path As String
Dim File As String

Path = "\\server\files\somewhere\toolongofapath"
File = Mail.Subject & "_" & Mail.ReceivedTime
ReplaceCharsForFileName File, "_"
Mail.Save File, olTXT

End Sub
 
Also Is it possible to put all of this code in another application? Like in
access?

so here is my idea,

From Access I run this little bit of code to save the email as a text file
to the folder, then move it to another folder (uploaded). Then the
application would run the rest of the data manipulation code that's already
built.
 
Unless the subfolder of Inbox is named "Mailbox - TheUgly_Data" it won't
work. Otherwise you'll have to step your code and see where you are getting
an error.
 
Application means Outlook.Application only in the Outlook VBA. In Access you
would have to use CreateObject("Outlook.Application") to get a reference to
the Outlook object. From there the code would be identical.
 
It is named the "Mailbox - TheUgly_Data". I went to the subfolder, right
clicked, chose properties and then copied and pasted the name from there into
the code.

It really is ugly data.

I'm guessing that is the way I would do it.

Thanks again.

I'm stepping through it now and think the issue is an object because it
freezes when I get to
File = Mail.Subject & "_" & Mail.ReceivedTime

A part of me thinks this should go infront of finding the folder not after.
I'm playing with it now. It's truely been a great learning experience
 
Well, it doesn't look like you're assigning Mail and if that's the case then
Mail would be null (Nothing).

Once you get the folder you need to get its Items collection and then
iterate that collection to look at each item. You also have to account for
the possibility that one or more of the items might not be a mail item, it
might be a post item or in Inbox it could be a meeting or task request or
something else.

Dim colItems As Outlook.Items
Dim Mail As Object

Set colItems = oTarget.Items
For Each Mail In colItems
If Mail.Class = olMail Then 'mail item
File = Mail.Subject & "_" & Mail.ReceivedTime
'whatever
End If
Next
 
Back
Top