+ Reply to Thread
Results 1 to 4 of 4

Macro to look at other opened Excel book

  1. #1
    Registered User
    Join Date
    10-18-2010
    Location
    NJ
    MS-Off Ver
    Excel 2007
    Posts
    73

    Macro to look at other opened Excel book

    I have a macro that does a vlookup on another Excel file that is already open based on the file name. I want to use this macro with Excel files that have different names. Is there any way to update my code below so it works with whatever other open Excel file exists and is not tied specifically to the file named below?

    My rational is that if I only have one other file open, it will always go to the correct file, regardless of the file name.

    Windows("Payroll Calc MACRO TEMPLATE 4-8-2013.xlsm").Activate

    I want it to be something like: Windows("Payroll Calc MACRO TEMPLATE*.xlsm").Activate
    Where the * represents various possible naming conventions.


    Thanks,
    Steve

  2. #2
    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: Macro to look at other opened Excel book

    Hi Steve,

    from what I understood (you could use InStr for the workbook name):
    Please Login or Register  to view this content.
    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

  3. #3
    Registered User
    Join Date
    10-18-2010
    Location
    NJ
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Macro to look at other opened Excel book

    Thanks - I'm confused about how to add this code to the following vlookup. The file named "Payroll Calc MACRO TEMPLATE 4-8-2013.xlsm" is the variable. It might be named something else. If it helps, I can restrict the naming convention so it always begins with "Payroll Calc."

    Windows("Vlookup Sheet.xlsx").Activate
    Range("M1").Select
    ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(RC[-1],'[Payroll Calc MACRO TEMPLATE 4-8-2013.xlsm]Template 1'!R13C2:R25C15,1,FALSE)"

    Quote Originally Posted by HaHoBe View Post
    Hi Steve,

    from what I understood (you could use InStr for the workbook name):
    Please Login or Register  to view this content.
    Ciao,
    Holger

  4. #4
    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: Macro to look at other opened Excel book

    Hi, Steve,

    I donīt understand why you check three columns wide and return the value from the first column as thatīs where VLookup will lookin exclusively.

    Please Login or Register  to view this content.
    And maybe avoid quoting full posts when answering - thanks.

    Ciao,
    Holger

+ 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