Public WithEvents myOlApp As Outlook.Application
Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.Application")
End Sub
Private Sub myOlApp_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Dim myItem As Outlook.MailItem
Set myExplorers = myOlApp.Explorers
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set myItem = myFolder.Items(1)--- which index value will give last received mail sender's mail id?
If myExplorers.Item(1).CurrentFolder.Name = "Inbox" Then
myExplorers.Item(1).Display
myExplorers.Item(1).Activate
If myItem.SenderName = "Charles A" Then
MsgBox ("Received")
Else
MsgBox myItem.SenderName
MsgBox myItem.Subject
MsgBox myItem.ReceivedTime
End If
Exit Sub
End If
End Sub
Source: http://www.outlookcode.com/codedetail.aspx?id=1089
Function FindEntry(ByVal filter As String, Optional ByVal SearchRoot As String = "") As DirectoryEntry
Dim ds As New DirectorySearcher
If SearchRoot <> "" Then ds.SearchRoot = New DirectoryEntry(SearchRoot)
ds.Filter = filter
ds.SearchScope = SearchScope.Subtree
ds.CacheResults = False
Dim sr = ds.FindOne
If sr Is Nothing Then Return Nothing
Return sr.GetDirectoryEntry
End Function
Dim ent = FindEntry("(&(CN=[groupname])(objectClass=group))")
Dim dn = ent.Properties("distinguishedName").Value
Function Ping(Target)
Dim results
On Error Resume Next
Set shell = CreateObject("wScript.Shell")
' Send 1 echo request, waiting 2 seconds for result
Set exec = shell.Exec("ping -n 1 -w 100 " & Target)
results = LCase(exec.StdOut.ReadAll)
Ping = (InStr(results, "reply from") > 0)
End Function
function funScrubStr(strTxt)
funScrubStr=replace(replace(replace(strTxt,"'","''")," & chr(34) & "," & chr(34) & chr(34) & "), ",", ",,")
end function