Within a For Each loop, I am using the WorksheetFunction.Find to locate a specific string in another string.
The find works on iteration 1 and 2 but on third gets:
Run-Time Error 1004 ... Unable to get the Find property of the WorksheetFunction class.
Here is the code:
Option Explicit
Sub MoveCCx()
Dim ccnumber As String
Dim Mybody As String
Dim MySubject As String
Dim MyTitlePointer As Integer
Dim olItems As Outlook.items
Dim olItem As Outlook.MailItem
Set olItems = session.getdefaultfolder(olfolderinbox).items
ccnumber = "1234-5678-8901-2345"
For Each olItem In olItems
MySubject = olItem.Subject
MsgBox MySubject, Buttons:=vbOKOnly
On Error GoTo NotFound
MyTitlePointer = 0
MyTitlePointer = WorksheetFunction.Find("WINTER", UCase(MySubject)) '<--PROBLEM
If MyTitlePointer > 0 Then
MsgBox "found Your " & MyTitlePointer & MySubject
Mybody = olItem.Body & ccnumber
olItem.Body = Mybody
Else
End If
NotFound:
Next olItem
End Sub
The Value of MySubject when the failure occurs is:
What am I doing on the first or second loop iteration to cause this?
I am running on Office 10 on Windows 7
The overall code is part of prototyping to see if I can add some text to specific emails (that have a keyword in the subject line) in my inbox. It works until the third email in the inbox.
Thanks for any help!
Bookmarks