Hello Team,
I have created a VBA script, to get an email received time from the subject title mentioned in the excel column.
The Excel will look like,
And, the Script is as below
Issue : When the script starts with Cell C1(which is a column title), it didn't find the matching subject in outlook so instead of going to the next cell the script ends directly.
If you guys can help me to sort this issue, the script should not end it should go to the next cell if didn't find the value specified in the cell.
Please note the script is going to the next cell if it finds the value in outlook and even we get the exact dates as well.
MOD EDIT: Added Code tags!
I have created a VBA script, to get an email received time from the subject title mentioned in the excel column.
The Excel will look like,
And, the Script is as below
Code:
Option Explicit
Sub Test()
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Object
Dim i As Integer, j As Integer
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders("DSD")
i = 1
For Each olMail In Fldr.Items
If Range("C" & i).Value <> "" Then
'MsgBox (Range("C" & i).Value)
If olMail.Subject = Range("C" & i).Value Then
'Range("A" & i).Value = olMail.Subject ' <-- output email name to column A
Range("B" & i).Value = olMail.ReceivedTime ' <-- output email sent date to column B
'olMail.Display ' show email through Excel
i = i + 1
End If
End If
Next olMail
End Sub
Issue : When the script starts with Cell C1(which is a column title), it didn't find the matching subject in outlook so instead of going to the next cell the script ends directly.
If you guys can help me to sort this issue, the script should not end it should go to the next cell if didn't find the value specified in the cell.
Please note the script is going to the next cell if it finds the value in outlook and even we get the exact dates as well.
MOD EDIT: Added Code tags!
Last edited by a moderator: