title: Excel VBA for searching String within an Outlook Attachment, flagging email if match is found
body: <p>Basically I have a list of 5000 strings populated in an Excel spreadsheet. I want VBA to go through the attachments in an Outlook Inbox and if it finds a string match, I want the particular email to be flagged. Here's the code I have so far</p>
  
  <pre><code>Sub attachsearch()
  On Error GoTo bigerror
  Dim ns As Namespace
  Dim inbox As MAPIFolder
  Dim subfolder As MAPIFolder
  Dim item As Object
  Dim atmt As Attachment
  Dim filename As String
  Dim i As Integer
  Dim varresponse As VbMsgBoxResult
  Dim workbk As Workbook
  Dim SearchString As String
  Set ns = GetNamespace("MAPI")
  Set inbox = ns.GetDefaultFolder(olFolderInbox)
  Set subfolder = inbox.Folders("test")
  Set workbk = Workbooks.Open("C:\Users\John.Doe\Desktop\10 25 2016 Pricing Team Macro.xlsm")
  i = 0
  If subfolder.Items.Count = 0 Then
  MsgBox "There are no emails to look at. Please stop wasting my time.", vbInformation, "Folder is Empty"
  Exit Sub
  End If
  For Each item In subfolder.Items
  For Each atmt In item.Attachments
  For rwindex = 1 To 5000
  SearchString = Workbooks("10 25 2016 Pricing Team Macro").Sheets("NDC Sort").Cells(rwindex, 1).Value
  </code></pre>
  
  <p>Below is the problem code, index proberty is not used correctly here, but I'm unsure what to use. I know that Microsoft indexes the words within the attachment because when I manually type in the search string in Outlook, it pulls up the email even though the string is only present within the attachment. So ultimately, my question is, how do I leverage that attachment index in VBA?</p>
  
  <pre><code>If atmt.Index Like "*" &amp; Workbooks("10 25 2016 Pricing Team Macro").Sheets("NDC Sort").Cells(rwindex, 1).Value &amp; "*" Then
  i = i + 1
  With item
      .FlagRequest = "Follow up"
      .Save
  End With
  End If
  Next rwindex
  Next atmt
  Next item
  If i &gt; 0 Then
  MsgBox "I found " &amp; i &amp; " attached files with a specific name."
  Else
  MsgBox "I didn't find any files"
  End If
  Set atmt = Nothing
  Set item = Nothing
  Set ns = Nothing
  workbk.Close savechanges:=False
  Exit Sub
  bigerror:
  MsgBox "something went wrong"
  End Sub
  </code></pre>
  
  <p>Any help would be greatly appreciated, thanks in advance!</p>