+ Reply to Thread
Results 1 to 12 of 12

How to code a macro to activate a workbook with a wildcard in the title

  1. #1
    Registered User
    Join Date
    07-08-2013
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    8

    How to code a macro to activate a workbook with a wildcard in the title

    My macro currently pulls the data I need out of a workbook "week of 7-21 to 7-27.xlsx". I want it to look to pull the data from any workbook that has a similar name (i.e. "week of **-** to **-**.xlsx).

    Here is the code I have:
    Please Login or Register  to view this content.
    Any help would be appreciated.
    Thank you.
    Last edited by Leith Ross; 08-29-2013 at 01:38 PM. Reason: Added Code tags

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

    Re: How to code a macro to activate a workbook with a wildcard in the title

    Hello processcker,

    I have converted your macro from a "macro recorder" version to more robust VBA code. Unless there is a specific reason you need to find the last cell by starting at the top and going down, it is a better practice to start at the bottom and come up. I left this part alone since I don't know the reason. It could be it is what the macro recorder inserted.
    Please Login or Register  to view this content.
    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!)

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to code a macro to activate a workbook with a wildcard in the title

    Hi processcker,

    I was trying to post this simultaneously with Leith's


    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    07-08-2013
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: How to code a macro to activate a workbook with a wildcard in the title

    Thank you Leith. In this case, I do need to find the last cell from the top, but there are some times I have started from the top, but could more easily have found the last cell from the bottom. I just don't know how.

    I tried what you gave me, but it didn't get past setting the destination workbook.

    I am very unfamiliar with VBA code, so I could have just done something wrong, but prior to this, the macro ran.

    Thank you for the input. I didn't realize I was doing this wrong from the start. I'll keep working at it.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to code a macro to activate a workbook with a wildcard in the title

    If Leith's code didn't work then my code probably doesn't -but did you try it?

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

    Re: How to code a macro to activate a workbook with a wildcard in the title

    Hello processcker,

    Did the macro display the message or did Excel? If Excel did then the macro stopped due to a system error. To help you further, I would need to know the error code number and the line in the macro where it stopped.

  7. #7
    Registered User
    Join Date
    07-08-2013
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: How to code a macro to activate a workbook with a wildcard in the title

    xladept,
    I'm sorry...this didn't work either. For starters, the source workbook is from a temporary drive, so I really just want to work from open workbooks only.

    I'm sure your code is good, but as Leith pointed out, I am going from a modified recording as opposed to true VBA code, so the issue really could be me and not what you provided.

    I do appreciate what you posted. I tried it and it certainly challenges me to think differently. Thank you.

  8. #8
    Registered User
    Join Date
    07-08-2013
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: How to code a macro to activate a workbook with a wildcard in the title

    The macro displayed an error requiring debugging. I'm afraid I'm just too new at this to even understand where I've messed up. I'm sorry for wasting your time.

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

    Re: How to code a macro to activate a workbook with a wildcard in the title

    Hello processcker,

    Which line of code is highlighted?

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to code a macro to activate a workbook with a wildcard in the title

    This will dump the non-productive book names at the end of the line - I think

    Please Login or Register  to view this content.
    Last edited by xladept; 08-30-2013 at 07:11 PM.

  11. #11
    Registered User
    Join Date
    07-08-2013
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: How to code a macro to activate a workbook with a wildcard in the title

    Thank you, with all of your help, I think I've finally got it working.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to code a macro to activate a workbook with a wildcard in the title

    You're welcome!

+ 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. Activate the open workbook (that doesn't contain the code!)
    By seaveegee in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2012, 10:23 AM
  2. activate and copy open workbook using a wildcard
    By sammar12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2012, 12:32 PM
  3. VBA Code: Activate Workbook Using Cell Value
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-17-2012, 12:55 PM
  4. Activate Workbook Using Wildcard
    By contra76 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2010, 05:10 PM
  5. Run a sheet's activate code when entering it's workbook
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-03-2005, 01:55 AM

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