Showing posts with label Accessing a folder by name and looping through items inside it in outlook using vba. Show all posts
Showing posts with label Accessing a folder by name and looping through items inside it in outlook using vba. Show all posts

Monday, September 20, 2021

Accessing a folder by name and looping through items inside it in outlook using python

 import win32com.client as client
import datetime,time
from os import path

outlook=client.Dispatch("Outlook.Application")

count = 0
olFolder = outlook.GetNamespace("MAPI").Folders("allsourav@hotmail.com").Folders("Sent Items")
#now let us loop through the mail items in that folder

for itmmail in olFolder.Items:
    

    if (itmmail.SentOnBehalfOfName =="allsourav@hotmail.com"):
        count = count + 1

print(count)

##Dim itmcount As Integer
itmcount = olFolder.Items.count
print(itmcount)
count = 0
##Dim x As Integer
##
##'reading mail older to newer
##
for x in range(1,itmcount):
##
    if (olFolder.Items(x).SentOnBehalfOfName == "allsourav@hotmail.com"):
        count = count + 1

print(count)
##
count = 0
##'reading mail in reverse order ,new to old
##
for x in range(itmcount,1,-1):
    if (olFolder.Items(x).SentOnBehalfOfName == "allsourav@hotmail.com"):
        count = count + 1
##End If
##Next x
print(count)

Sunday, September 19, 2021

Accessing a folder by name and looping through items inside it in outlook using vba

 Sub accessFolderbyName()

Dim olApp, olAccts, olInspect As Object
Set olApp = CreateObject("Outlook.Application")
Dim olFolder As Outlook.MAPIFolder
Dim count As Integer
count = 0
Set olFolder = olApp.GetNamespace("MAPI").Folders("allsourav@hotmail.com").Folders("Sent Items")
'now let us loop through the mail items in that folder

For Each itmmail In olFolder.Items

If itmmail.SentOnBehalfOfName = "allsourav@hotmail.com" Then
count = count + 1
End If
Next itmmail
MsgBox (count)

Dim itmcount As Integer
itmcount = olFolder.Items.count
MsgBox itmcount
count = 0
Dim x As Integer

'reading mail older to newer

For x = 1 To itmcount

If olFolder.Items(x).SentOnBehalfOfName = "allsourav@hotmail.com" Then
count = count + 1
End If
Next x
MsgBox (count)

count = 0
'reading mail in reverse order ,new to old

For x = itmcount To 1 Step -1

If olFolder.Items(x).SentOnBehalfOfName = "allsourav@hotmail.com" Then
count = count + 1
End If
Next x
MsgBox (count)

End Sub