PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Create Folders based on domain name
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Create Folders based on domain name
![]() |
Create Folders based on domain name |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I wand to run though my full inbox and create a subfolder for each of the domain names therein, but leaving off the extension (.com, .org, .co.uk etc). For example, my inbox has 100 e-mails from a total of 25 different company domain names, e.r 10 from xxx@Walker.co.uk, 11 from tgyell@Spaceage.com, 5 from kenny.wills@Franksome.co.uk I therefore wand a folder called: Walker, Spaceage and Franksome Thanks again |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Thanks for that.
I need the vba to determine the folder names for me, based on the e-mail addresses it finds in my inbox, and then create the folders... ? I do not want to have to manually go through my e-mails myself and decide what folders are needed thanks again "Dmitry Streblechenko" wrote: > set Inbox = Application.Session.(olFolderInbox) > set NewSubFolder = Inbox.Folders.Add("Your new folder name") > > Dmitry Streblechenko (MVP) > http://www.dimastr.com/ > OutlookSpy - Outlook, CDO > and MAPI Developer Tool > > "S1lverface" <S1lverface@discussions.microsoft.com> wrote in message > news:44BA55B2-D6CE-40F7-BF6B-5CB77A657206@microsoft.com... > > > > I wand to run though my full inbox and create a subfolder for each of the > > domain names therein, but leaving off the extension (.com, .org, .co.uk > > etc). > > > > For example, my inbox has 100 e-mails from a total of 25 different company > > domain names, e.r 10 from xxx@Walker.co.uk, 11 from tgyell@Spaceage.com, 5 > > from kenny.wills@Franksome.co.uk > > > > I therefore wand a folder called: Walker, Spaceage and Franksome > > > > Thanks again > > > > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
set Inbox = Application.Session.(olFolderInbox)
set NewSubFolder = Inbox.Folders.Add("Your new folder name") Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "S1lverface" <S1lverface@discussions.microsoft.com> wrote in message news:44BA55B2-D6CE-40F7-BF6B-5CB77A657206@microsoft.com... > > I wand to run though my full inbox and create a subfolder for each of the > domain names therein, but leaving off the extension (.com, .org, .co.uk > etc). > > For example, my inbox has 100 e-mails from a total of 25 different company > domain names, e.r 10 from xxx@Walker.co.uk, 11 from tgyell@Spaceage.com, 5 > from kenny.wills@Franksome.co.uk > > I therefore wand a folder called: Walker, Spaceage and Franksome > > Thanks again > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Thanks again...
I've spent the las hour trying to work it out, and failed. Below is the code I've used to manually create 5 folder names based on e-mail domain names from my inbox. I want it to go through the inbox and find these and others and create me the folders. I'm too new to VBA to understand the 'loop', 'parse' etc, but I do learn and follow examples well. I'm not sure where to put or what to put... If you could help that'd be great... Good news though is that I'm hoping to get an outlook vba programming book for my Xmas.... Its on my list! But in the meantime, all help is great..... S1lverface :-) '---------------------------------------------------------- Sub SetUpFolders() Dim oloUtlook As Outlook.Application Dim ns As Outlook.NameSpace Dim itm As Object On Error Resume Next Application.ScreenUpdating = False Set oloUtlook = CreateObject("Outlook.Application") Set ns = oloUtlook.GetNamespace("MAPI") Set itm = ns.GetDefaultFolder(olFolderInbox) itm.Folders.Add ("Fruitmarket") itm.Folders.Add ("Sales") itm.Folders.Add ("Blythe") itm.Folders.Add ("Yeoman") itm.Folders.Add ("Network") Set oloUtlook = Nothing Set ns = Nothing Set itm = Nothing MsgBox "All Done" ThisWorkbook.Close End Sub '----------------------------------------------------- "S1lverface" wrote: > Thanks for that. > I need the vba to determine the folder names for me, based on the e-mail > addresses it finds in my inbox, and then create the folders... ? I do not > want to have to manually go through my e-mails myself and decide what folders > are needed > > thanks again > > "Dmitry Streblechenko" wrote: > > > set Inbox = Application.Session.(olFolderInbox) > > set NewSubFolder = Inbox.Folders.Add("Your new folder name") > > > > Dmitry Streblechenko (MVP) > > http://www.dimastr.com/ > > OutlookSpy - Outlook, CDO > > and MAPI Developer Tool > > > > "S1lverface" <S1lverface@discussions.microsoft.com> wrote in message > > news:44BA55B2-D6CE-40F7-BF6B-5CB77A657206@microsoft.com... > > > > > > I wand to run though my full inbox and create a subfolder for each of the > > > domain names therein, but leaving off the extension (.com, .org, .co.uk > > > etc). > > > > > > For example, my inbox has 100 e-mails from a total of 25 different company > > > domain names, e.r 10 from xxx@Walker.co.uk, 11 from tgyell@Spaceage.com, 5 > > > from kenny.wills@Franksome.co.uk > > > > > > I therefore wand a folder called: Walker, Spaceage and Franksome > > > > > > Thanks again > > > > > > > > > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Loop through all messages in your inbox, read the SenderEmailAddres
property, parse it, add it to a list of folders to create if it is not already there. Then loop through the list and create subfolders. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "S1lverface" <S1lverface@discussions.microsoft.com> wrote in message news:EAD23335-6532-4C9C-994C-C9EB0EFE5C9A@microsoft.com... > Thanks for that. > I need the vba to determine the folder names for me, based on the e-mail > addresses it finds in my inbox, and then create the folders... ? I do not > want to have to manually go through my e-mails myself and decide what > folders > are needed > > thanks again > > "Dmitry Streblechenko" wrote: > >> set Inbox = Application.Session.(olFolderInbox) >> set NewSubFolder = Inbox.Folders.Add("Your new folder name") >> >> Dmitry Streblechenko (MVP) >> http://www.dimastr.com/ >> OutlookSpy - Outlook, CDO >> and MAPI Developer Tool >> >> "S1lverface" <S1lverface@discussions.microsoft.com> wrote in message >> news:44BA55B2-D6CE-40F7-BF6B-5CB77A657206@microsoft.com... >> > >> > I wand to run though my full inbox and create a subfolder for each of >> > the >> > domain names therein, but leaving off the extension (.com, .org, .co.uk >> > etc). >> > >> > For example, my inbox has 100 e-mails from a total of 25 different >> > company >> > domain names, e.r 10 from xxx@Walker.co.uk, 11 from >> > tgyell@Spaceage.com, 5 >> > from kenny.wills@Franksome.co.uk >> > >> > I therefore wand a folder called: Walker, Spaceage and Franksome >> > >> > Thanks again >> > >> >> >> |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Off the top of my head, don't know if it'll actually work:
On error resume next 'to be able to handle errors returened by Inbox.Folders() Set oloUtlook = CreateObject("Outlook.Application") Set ns = oloUtlook.GetNamespace("MAPI") Set Inbox = ns.GetDefaultFolder(olFolderInbox) for each Msg in Inbox.Items if Msg.Class = 43 Then address = Msg.SenderEmailAddress AddrParts = split(address, ".") if UBound(AddrParts) >= 1 Then FolderName = AddrParts(UBound(AddrParts)-1) 'second last part err.Clear set Folder = Inbox.Folders(FolderName) if err.Number <> 0 Then 'the folder does not exist set Folder = Inbox.Folders.Add(FolderName) End If End If End If next Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "S1lverface" <S1lverface@discussions.microsoft.com> wrote in message news:ACC4776F-F222-4634-A46B-54E1CE73F220@microsoft.com... > Thanks again... > I've spent the las hour trying to work it out, and failed. > > Below is the code I've used to manually create 5 folder names based on > e-mail domain names from my inbox. I want it to go through the inbox and > find > these and others and create me the folders. I'm too new to VBA to > understand > the 'loop', 'parse' etc, but I do learn and follow examples well. I'm not > sure where to put or what to put... If you could help that'd be great... > Good > news though is that I'm hoping to get an outlook vba programming book for > my > Xmas.... Its on my list! But in the meantime, all help is great..... > S1lverface :-) > > > '---------------------------------------------------------- > Sub SetUpFolders() > Dim oloUtlook As Outlook.Application > Dim ns As Outlook.NameSpace > Dim itm As Object > > On Error Resume Next > > Application.ScreenUpdating = False > > Set oloUtlook = CreateObject("Outlook.Application") > Set ns = oloUtlook.GetNamespace("MAPI") > Set itm = ns.GetDefaultFolder(olFolderInbox) > > itm.Folders.Add ("Fruitmarket") > itm.Folders.Add ("Sales") > itm.Folders.Add ("Blythe") > itm.Folders.Add ("Yeoman") > itm.Folders.Add ("Network") > > Set oloUtlook = Nothing > Set ns = Nothing > Set itm = Nothing > > MsgBox "All Done" > ThisWorkbook.Close > > End Sub > '----------------------------------------------------- > "S1lverface" wrote: > >> Thanks for that. >> I need the vba to determine the folder names for me, based on the e-mail >> addresses it finds in my inbox, and then create the folders... ? I do not >> want to have to manually go through my e-mails myself and decide what >> folders >> are needed >> >> thanks again >> >> "Dmitry Streblechenko" wrote: >> >> > set Inbox = Application.Session.(olFolderInbox) >> > set NewSubFolder = Inbox.Folders.Add("Your new folder name") >> > >> > Dmitry Streblechenko (MVP) >> > http://www.dimastr.com/ >> > OutlookSpy - Outlook, CDO >> > and MAPI Developer Tool >> > >> > "S1lverface" <S1lverface@discussions.microsoft.com> wrote in message >> > news:44BA55B2-D6CE-40F7-BF6B-5CB77A657206@microsoft.com... >> > > >> > > I wand to run though my full inbox and create a subfolder for each of >> > > the >> > > domain names therein, but leaving off the extension (.com, .org, >> > > .co.uk >> > > etc). >> > > >> > > For example, my inbox has 100 e-mails from a total of 25 different >> > > company >> > > domain names, e.r 10 from xxx@Walker.co.uk, 11 from >> > > tgyell@Spaceage.com, 5 >> > > from kenny.wills@Franksome.co.uk >> > > >> > > I therefore wand a folder called: Walker, Spaceage and Franksome >> > > >> > > Thanks again >> > > >> > >> > >> > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

