+ Reply to Thread
Results 1 to 6 of 6

Why doesn't a wildcard work for a workbook name compare?

Hybrid View

garygomes Why doesn't a wildcard work... 07-18-2012, 07:56 PM
jindon Re: Why doesn't a wildcard... 07-18-2012, 08:03 PM
Leith Ross Re: Why doesn't a wildcard... 07-18-2012, 08:03 PM
garygomes Re: Why doesn't a wildcard... 07-18-2012, 08:07 PM
Leith Ross Re: Why doesn't a wildcard... 07-18-2012, 08:24 PM
Cutter Re: Why doesn't a wildcard... 07-18-2012, 08:26 PM
  1. #1
    Registered User
    Join Date
    04-09-2010
    Location
    Union City, California
    MS-Off Ver
    Excel 2007
    Posts
    4

    Why doesn't a wildcard work for a workbook name compare?

    The wildcards does not appear to function in this line of code:

    If wbBook.Name = "*FARF*.xlsm" Then
    The IF statement never finds a match though I know a workbook with a name containing 'FARF' is open.
    Last edited by Cutter; 07-18-2012 at 08:25 PM. Reason: Added code tags

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Why doesn't a wildcard work for a workbook name compare?

    = operator doesn't recognise wild cards, so use Like operator.
    If wbBook.Name Like "*FARF*.xlsm"

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Why doesn't a wildcard work for a workbook name compare?

    Hello garygomes,

    Welcome to the Forum!

    In VBA, the wild cards must be used with the LIKE operator. However, the LIKE operator is case sensitive. Your code will work if written as below and the name is in all capitals.
    If wbBook.Name Like "*FARF*.xlsm" Then
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    04-09-2010
    Location
    Union City, California
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Why doesn't a wildcard work for a workbook name compare?

    you guys rock! Thanks!

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Why doesn't a wildcard work for a workbook name compare?

    Hello garygomes,

    You're welcome. Are in the Union City across from the Haystack?

  6. #6
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Why doesn't a wildcard work for a workbook name compare?

    @garygomes

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself.
    Thanks.

    Also as a new (or relatively new) poster in the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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