+ Reply to Thread
Results 1 to 6 of 6

Adjust code for variable workbook title

  1. #1
    Forum Contributor
    Join Date
    01-05-2017
    Location
    New York
    MS-Off Ver
    Office 2016
    Posts
    206

    Adjust code for variable workbook title

    I have the following code:

    Please Login or Register  to view this content.
    The issues are with the workbooks references
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    . And all subsequent instances of these workbook references.

    Sometimes "Book3" is named "Book1", sometimes it is "Book2", etc. The same thing for "CatalogListing-2.xlsx", some times it is "CatalogListing-1.xlsx", sometimes it is "CatalogListing (2).xlsx" etc.

    Can someone help me adjust the code so that it would work for "Book*" (wildcard) and for "CatalogListing*.xlsx" (wildcard)?

    Thank you!

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Adjust code for variable workbook title

    Will this work?

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Adjust code for variable workbook title

    What is creating Book1, 2 ,3 etc...?

    I think we need to see that portion of the code to help you out here.
    -If you think you are done, Start over - ELeGault

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,032

    Re: Adjust code for variable workbook title

    If Book* is active when the macro is run, then you could use ActiveWorkbook. But I suspect it is not. In which case, you could loop through the open workbooks to find the first workbook that begins with "Book". Or, you could get the macro itself to create a new workbook using Workbooks.Add. This would become the ActiveWorkbook so you could Name it and set a reference to it for later use.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Adjust code for variable workbook title

    My original post probably works, but as others have brought up, the ideal scenario is to work with a workbook object that you can set when the code creates or opens the other books, assuming that is done through code... a more complete code post might help us find the best solution...

  6. #6
    Forum Contributor
    Join Date
    01-05-2017
    Location
    New York
    MS-Off Ver
    Office 2016
    Posts
    206

    Re: Adjust code for variable workbook title

    How about before the actual code runs an input box will open with "Select the workbooks you will be using"

    Is that possible?

+ 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. CSV Import (Done) - Find Title, Compare and adjust Inventory
    By Denni88 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2016, 10:21 AM
  2. Replies: 1
    Last Post: 11-06-2015, 08:35 AM
  3. [SOLVED] assign sheet to variable by code name in another workbook
    By karen53 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-17-2014, 11:27 PM
  4. Calling a sub in another workbook then using a variable from it in my own code.
    By kadeo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-03-2014, 06:52 AM
  5. [SOLVED] How to code a macro to activate a workbook with a wildcard in the title
    By processcker in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-12-2013, 03:25 PM
  6. SKU code generation from Workbook title
    By vorsta in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2013, 08:59 AM
  7. Code to reference variable named workbook?
    By ajava in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2009, 08:22 PM

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