Hello All,

I have got a VBA script in outlook which checks for the subject of the mail if it contains some text and then checks whether or not that text is present in an already exisitng excel sheet.If it is present then it will update another excel sheet with the subject,body.Ann if that text is not present in that sheet then it will not upadte that another sheet.

But what is happening is it is updating that new sheet if that text is not present also in the exisiting excel sheet which is taking from the subject.And one more thing is that this script is running only on my system,not working on any other system.
I am attaching the VBA code for reference.
VBA Code:
  1. Function CheckText(CellToCheck As Range, KeyString As String) As Boolean
  2.     Dim CheckRange As Range, Hit As Range
  3.     Set Hit = CellToCheck.Find(what:=KeyString, LookIn:=xlValues, Lookat:=xlWhole, MatchCase:=False)
  4.     CheckText = Not (Hit Is Nothing)
  5. End Function
  6.  
  7. Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
  8. Dim CheckRange As Range
  9. Dim KeyString As String
  10. vID = Split(EntryIDCollection, ",")
  11. Set XLApp1 = CreateObject("Excel.Application")
  12. Set CheckRange = XLApp1.Workbooks.Open("C:\Users\vijaywp\Desktop\India-IR-Schedule.xlsx").Sheets("Client Testing").Range("A1:S100")
  13. For i = 0 To UBound(vID)
  14. Set objMail = Application.Session.GetItemFromID(vID(i))
  15. vSubject = objMail.Subject
  16. vBody = objMail.Body
  17. vFrom = objMail.SenderEmailAddress
  18. VRtime = objMail.SentOn
  19. KeyString = Mid(Trim(Mid(vSubject, InStr(vSubject, "#") + 1)), 1, 3)
  20. If CheckText(CheckRange, KeyString) = True Then
  21.  
  22.    Set XLApp = CreateObject("Excel.Application")
  23.    Set xlWB = XLApp.Workbooks.Open("C:\Users\vijaywp\Desktop\sample.xlsx")
  24.    Set xlSheet = xlWB.Sheets("Sheet1")
  25.    vRow = xlSheet.Range("A" & XLApp.Rows.Count).End(-4162).Offset(1, 0).Row
  26.    xlSheet.Range("A" & vRow).Value = vSubject
  27.    xlSheet.Range("B" & vRow).Value = vBody
  28.    xlSheet.Range("C" & vRow).Value = VRtime
  29.    xlWB.Save
  30.    XLApp.Quit
  31.    Set objMail = Nothing
  32.    Set XLApp = Nothing
  33.  
  34. End If
  35. Next i
  36. XLApp1.DisplayAlerts = False
  37. XLApp1.Quit
  38. XLApp1.DisplayAlerts = True
  39. Set XLApp1 = Nothing
  40. End Sub

Please help me on this one guys.

Thanks in advance.