+ Reply to Thread
Results 1 to 4 of 4

Find Property of Worksheet Function Class

Hybrid View

  1. #1
    Registered User
    Join Date
    02-18-2009
    Location
    Apex, NC, USA
    MS-Off Ver
    Office 365
    Posts
    64

    Find Property of Worksheet Function Class

    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:

    PHP Code: 
    Dan BlumEnjoy clearsimple pricing from the trusted name in online payments
    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!
    Last edited by DanBlum; 12-01-2014 at 09:09 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Find Property of Worksheet Function Class

      MyTitlePointer = InStr(UCase(MySubject), "WINTER")
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Find Property of Worksheet Function Class

    WorksheetFunctions cause errors when they return an error value.
    Try Dim MyTitlePointer as Variant
    
    '...
    MyTitlePointer = Application.Find("WINTER", UCase(MySubject))
    If IsError(myTitlePointer) then 
        MsgBox "Winter not there"
        Exit Sub
    End If

    Edit: I like shg's InStr as a better solution.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    02-18-2009
    Location
    Apex, NC, USA
    MS-Off Ver
    Office 365
    Posts
    64

    Re: Find Property of Worksheet Function Class

    Thanks guys!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] unable to get the vlookup property of the worksheet function class
    By zak.horrocks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-17-2014, 09:35 AM
  2. unable to get the vlookup property of the worksheet function class
    By zak.horrocks in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2014, 08:01 AM
  3. [SOLVED] unable to get the sumif property of the worksheet function class -> HELP!!!
    By stadjer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2012, 07:32 AM
  4. Unable to Match property of Worksheet class function
    By bambino_32 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2010, 05:38 AM
  5. Unable to get countif property of the worksheet function class
    By mikeyfear in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2008, 06:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1