+ Reply to Thread
Results 1 to 6 of 6

VBA: 2 open workbooks; 1 unknown; activating the unknown one

  1. #1
    Registered User
    Join Date
    01-05-2014
    Location
    France
    MS-Off Ver
    Excel 2003
    Posts
    5

    VBA: 2 open workbooks; 1 unknown; activating the unknown one

    Good afternoon everyone,

    I can't figure this out:

    I have a VBA code that operates on two workbooks that we receive by email. One workbook always has the same name; the other workbook name always changes. The code needs to start on the workbook with the unknown name. In other terms, the code should represent:


    If activeworkbook.name = "Knownworkbookname" then Unknownworkbook.activate


    Thank you for any help.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA: 2 open workbooks; 1 unknown; activating the unknown one

    How are the workbooks being opened?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-05-2014
    Location
    France
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA: 2 open workbooks; 1 unknown; activating the unknown one

    Just from emails. Two excel workbooks are attached to emails that we receive regularly. The attachments are simply clicked on to open the workbooks, one after the other. The second opened workbook will be the ActiveWorkbook of course.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA: 2 open workbooks; 1 unknown; activating the unknown one

    So where are you running the code from, a third workbook?

  5. #5
    Registered User
    Join Date
    01-05-2014
    Location
    France
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA: 2 open workbooks; 1 unknown; activating the unknown one

    Yes: The code is written in the Personal workbook (the hidden workbook). To run the macro (in Excel 2010) I click on:

    View;Macro;"relevant macro"

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA: 2 open workbooks; 1 unknown; activating the unknown one

    Hi, Janis Rainis,

    loop through the workbooks in the instance of Excel and exit loop when condition is met:
    Please Login or Register  to view this content.
    I agree with Norie to open and reference the workbooks from within the macro. If you want to omitt the extension you may use Like or InStr to compare teh workbook names or your a Select Case instead of multiple Ifs.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ 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. [SOLVED] VBA - Open an unknown file name with known date in
    By dgo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2013, 12:47 PM
  2. Activating another open workbook with unknown name
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2010, 03:17 PM
  3. Summing across unknown range in unknown cell!
    By agentred in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 10-28-2009, 10:10 AM
  4. Open WB located in an unknown path - VBA
    By ElmerS in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 06-22-2009, 04:01 PM
  5. [SOLVED] Open unknown file name
    By Jan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-08-2006, 10:55 PM

Tags for this Thread

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