Solved

Outlook Macro

Posted on 2013-10-22
21
388 Views
Last Modified: 2013-11-07
Hi

I am managing 9 outlook inboxes with various subfolders. Is it possible to create a report in excel via macro with a break down like how many email received every half an hour in the whole day across each inbox.

Thanks
Output in Excel
\\\customerservice\     8:00-8:30 am - 10
\\\customerservice\      8:30 - 9:00  - 12
\\\customerservice\     9:00 - 9:30  - 14
0
Comment
Question by:surah79
  • 9
  • 9
21 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39623605
surah79

Can you confirm which version of outlook is in use and whether you need to run the script from excel or outlook?

Chris
0
 

Author Comment

by:surah79
ID: 39626242
14.0.6129.5000(32 bit) from outlook but excel is also fine.
Thanks
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39626576
I haven't a clue what the number means … can you talk in terms of the 'common' designation for example outlook 2010 / 2011 / 2013?

note if I use the example of mine then its 14 something in the full version but outlook 2011 in the common 'version'.  I recognise when I say version you have responded literally but what i need is the boxed version rather than the low level detail.

Chris
0
 

Author Comment

by:surah79
ID: 39626717
Outlook 2010
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39627049
Version is good to allow most things, when you say inbox folders are these sub folders of the one inbox or multiple psts each of which has an inbox?

Chris
0
 

Author Comment

by:surah79
ID: 39628034
Yes multiple sub folder in one inbox,so I will keep changing the inbox name to generate the report for the other inbox with multiple folder and then combine everything
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39628044
Sorry but trying to get my head around this:

pst1
    inbox
        folder 1
        folder 2
        …
        folder n
pst2
    inbox
        folder a
        folder b
        …
        folder z

pstn
    inbox
        folder 1a
        folder 2b
        …
        folder nz

or something else

Chris
0
 

Author Comment

by:surah79
ID: 39628110
Yep
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39628164
I believe something can be done but processing so many sub folders will take some time so how far down do we need to go all sub folders or just the first level and do you want the mails identifying against the past or by folder?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:surah79
ID: 39629180
Hi just want to go all sub folder down ;mails identifying against  should be the time slot
8:30 - 9:30  20
9:30 - 10:00 30
Then I can run 9 times at diff inboxes separately and make the combine report
Inbox structure is as below
Inboxa
  Sybfolder1
  SSub folder 2
Sub folder 3
Sub folder 4
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39629462
I was assuming you wanted one script that ran through all the psts?

My latest question however was do you want:

\\\customerservice\     8:00-8:30 am - 10
\\\customerservice\      8:30 - 9:00  - 12

or

\\\customerservice\     8:00-8:30 am - 2
\\\customerservice\subfolder1     8:00-8:30 am - 5
\\\customerservice\Subsubfolder1     8:00-8:30 am - 3
etc

Chris
0
 

Author Comment

by:surah79
ID: 39629464
Second one with the sub folder
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39629889
I have some test code that evidences the basics to meet this however at the moment it processes folders then times and this is another area where the requirement needs refining:

\\\customerservice\     8:00-8:30 am - 2
\\\customerservice\     8:30-9:00 am - 1
\\\customerservice\     9:00-9:30 am - 5

\\\customerservice\subfolder1     8:00-8:30 am - 3
\\\customerservice\subfolder1     8:30-9:00 am - 5
\\\customerservice\subfolder1     9:00-9:30 am - 2

or

\\\customerservice\     8:00-8:30 am - 2
\\\customerservice\subfolder1     8:00-8:30 am - 3
\\\customerservice\     8:30-9:00 am - 1
\\\customerservice\subfolder1     8:30-9:00 am - 5
\\\customerservice\     9:00-9:30 am - 5
\\\customerservice\subfolder1     9:00-9:30 am - 2

Chris
0
 

Author Comment

by:surah79
ID: 39629976
Second one
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 39630660
This should do it then

Sub Q28274550_1()
Dim acct As Account
Dim fldr As MAPIFolder
Dim arr As Variant
Dim intArraySize As Integer
Dim elem As Integer
Dim xlapp As Object
Dim xlWB As Object
Dim xlSh As Object

    intArraySize = 0
    ReDim arr(2, 0)
    For Each acct In Application.Session.Accounts
        ReDim Preserve arr(2, intArraySize)
        Set fldr = Application.Session.GetFolderFromID(acct.DeliveryStore.StoreID).Folders("Inbox")
        Q28274550_1a fldr, intArraySize, arr
    Next
    Set xlapp = CreateObject("excel.application")
    xlapp.Visible = False
    xlapp.screenupdating = False
    xlapp.enableevents = False
    Set xlWB = xlapp.workbooks.Add
    Set xlSh = xlWB.sheets(1)
    For elem = 0 To UBound(arr, 2)
'        Debug.Print arr(0, elem) & "<>" & arr(1, elem) & "<>" & arr(2, elem)
        xlSh.cells(elem + 1, 1) = arr(0, elem)
        xlSh.cells(elem + 1, 2) = arr(1, elem)
        xlSh.cells(elem + 1, 3) = arr(2, elem)
    Next
    
    With xlSh.Sort
        .SortFields.Add Key:=xlSh.Range("B1:B100") _
            , SortOn:=0, Order:=1, DataOption:=0
        .SortFields.Add Key:=xlSh.Range("A1") _
            , SortOn:=0, Order:=1, DataOption:=0
        .SetRange xlSh.cells
        .Header = 2
        .MatchCase = False
        .Orientation = 1
        .SortMethod = 1
        .Apply
    End With
    
    
    xlSh.Range("1:3").Columns.autofit
    xlapp.screenupdating = True
    xlapp.enableevents = True
    xlapp.Visible = True

End Sub

Function Q28274550_1a(fldr As MAPIFolder, intArraySize As Integer, arr As Variant)
Dim subFolder As MAPIFolder
Dim strFilter As String
Dim lngItemCount As Long
Dim strStarttime As String
Dim strFinishTime As String
Dim folderItems As Object
Dim strStart As String
Dim varStart As Variant
Dim strEnd As String
Dim varEnd As Variant
Dim varPeriod As Variant
Dim strIncrement As Integer
Dim varIncrement As Variant

    strStart = "08:00:00"
    strEnd = "17:00:00"
    strIncrement = 30
    varStart = TimeValue(strStart)
    varEnd = TimeValue(strEnd)
    varIncrement = TimeValue("00:" & strIncrement & ":00")
    For varPeriod = varStart To varEnd Step varIncrement
        strStarttime = Format(Date + varPeriod, "ddddd h:nn AMPM")
        strFinishTime = Format(DateAdd("n", strIncrement, Date + varPeriod), "ddddd h:nn AMPM")
        strFilter = "[ReceivedTime] >= '" & strStarttime & "'" & " and " & "[ReceivedTime] < '" & strFinishTime & "'"
        Set folderItems = fldr.Items.Restrict(strFilter)
        lngItemCount = folderItems.Count
        ReDim Preserve arr(2, intArraySize)
        arr(0, intArraySize) = fldr.FolderPath
        arr(1, intArraySize) = Format(strStarttime, "hh:mm") & " - " & Format(strFinishTime, "hh:mm")
        arr(2, intArraySize) = lngItemCount
        intArraySize = intArraySize + 1
    Next
    
'    Debug.Print fldr.FolderPath & " <> " & lngItemCount
    For Each subFolder In fldr.Folders
        Q28274550_1a subFolder, intArraySize, arr
    Next

End Function

Open in new window


Chris
0
 

Author Closing Comment

by:surah79
ID: 39631895
Chris you are awesome. Thanks a million, you are saviour
0
 

Author Comment

by:surah79
ID: 39631918
Hi Chris

Can I open another question and ask you If have to use this  for  another  Shared Inbox where I have to put his address

Thanks
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39631927
Hmmm

I guess it should be doable though it would need a different call I think the overall process will work much the same for the shared inbox. so ask away and someone will answer … the hard bit is done I think and i'll think about it a bit myself

Chris
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Use email signature images to promote corporate certifications and industry awards.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now