Consulting

Results 1 to 5 of 5

Thread: Solved: Test for a string in a active workbook name

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Solved: Test for a string in a active workbook name

    How can I test for a string in an activeworkbooks name?

    I tried this:

    [VBA]If activeworkbook.name = "*est*" then[/VBA]

    I though a wildcard character would work but it didn't.
    Thank You,
    Daniel Blois
    http://studenthacker.blogspot.com/

  2. #2
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Daniel,

    Replace the "=" sign with LIKE. Here is what Help has to say:

    "Like Operator Example (Microsoft Excel)
    This example deletes every defined name that contains "temp". The Option Compare Text statement must be included at the top of any module that contains this example.

    For Each nm In ActiveWorkbook.Names
    If nm.Name Like "*temp*" Then
    nm.Delete
    End If
    Next nm"

    Cheers,
    Ron
    Windermere, FL

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Thank you that worked perfectly. so whenever I want to use a wild character I need to use like?
    Thank You,
    Daniel Blois
    http://studenthacker.blogspot.com/

  4. #4
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Yes, if you are searching for the existence of a substring within a test string.

    Cheers,
    Ron
    Windermere, FL

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can also use InStr

    [vba]

    If InStr(nm.Name, "temp") > 0 Then
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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