+ Reply to Thread
Results 1 to 4 of 4

How to switch to an open window with a wildcard file name

  1. #1
    Registered User
    Join Date
    01-08-2014
    Location
    Bath, UK
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    86

    How to switch to an open window with a wildcard file name

    Hi,

    I usually have 2-3 files open when running this process and download a file from a web based program which opens an Excel file which is usually called "PL Invoices" but is sometimes called "PL Invoices (1)" or "PL Invoices (2)" (I've not seen higher numbers, but I suspect they're possible - the numbers seem to relate to the number of times I've run the report (e.g. if the macro crashed because I forgot to change something), so I am unlikely to get PL Invoices (3) or higher, if that helps).

    I am trying to activate this file so I can copy and paste data (in the rest of the macro) into another file inconveniently called "PL Invoices 16/17" (relating to the financial year).
    In the rest of the process I need to swap and change a couple of times between the files, so it would be nice to find/obtain the file name and be able to use it as a variable.

    Can you help, please?

    Thanks :-)

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to switch to an open window with a wildcard file name

    Cycle through the open workbooks looking for a matching name and then attach the found workbook name to workbook object variable, then use that variable name from then on.
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-08-2014
    Location
    Bath, UK
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    86

    Re: How to switch to an open window with a wildcard file name

    Hi Jerry,

    Thanks for the code. It looks as though the code is specifically looking for a file called "PL Invoices". Unfortunately, the file I download can be called "PL Invoices", "PL Invoices(1)" or "PL Invoices(2)" (theoretically there could be 3, 4, etc, but I have only ever seen blank, 1 or 2 so am happy to work with that.

    Also, in the next part of the code, I am trying to activate that particular file... the specific code, below, worked fine...
    'Windows("PL_Invoices.xls").Activate

    However, when I try to use the variable sheet name, it doesn't work - do I need to do something else so I can use the variable file name?
    Windows(wbSRC).Activate


    Thanks,
    Graham

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to switch to an open window with a wildcard file name

    No, the code is looking for the string "PL Invoice" in the names of all open workbooks. Instr() is a "find" tool.

    We've set a workbook variable, so keep using it as the OBJECT, not a string source.
    Please Login or Register  to view this content.

+ 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. Switch from Active Window to Variable Window/Rename Varaible Sheet
    By CravingGod in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-04-2016, 09:52 AM
  2. VBA - Open file with wildcard in path
    By bshawn in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-23-2015, 08:31 PM
  3. Replies: 8
    Last Post: 11-25-2015, 08:14 PM
  4. use VBA to switch to an new IE window that has opened behind main IE window.
    By Andy Mcc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2015, 09:16 AM
  5. [SOLVED] Open file code switch off when name changed
    By Wales MB in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-07-2013, 03:17 PM
  6. Replies: 2
    Last Post: 01-24-2013, 04:56 PM
  7. Open File or Switch Between Windows if File is Open
    By Ricky Pang in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-08-2005, 01:05 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