• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

Outlook Macro

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
surah79
Asked:
surah79
  • 9
  • 9
1 Solution
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
 
surah79Author Commented:
14.0.6129.5000(32 bit) from outlook but excel is also fine.
Thanks
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
surah79Author Commented:
Outlook 2010
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
 
surah79Author Commented:
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
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
 
surah79Author Commented:
Yep
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
 
surah79Author Commented:
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
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
 
surah79Author Commented:
Second one with the sub folder
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
 
surah79Author Commented:
Second one
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
 
surah79Author Commented:
Chris you are awesome. Thanks a million, you are saviour
0
 
surah79Author Commented:
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
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now