+ Reply to Thread
Results 1 to 5 of 5

How to evaluate an workbook object by its name in code?

  1. #1
    Registered User
    Join Date
    06-28-2011
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    4

    How to evaluate an workbook object by its name in code?

    Declaration:
    Private wbAcctFees As Workbook

    Please Login or Register  to view this content.
    Formula in a Cell:
    =VLOOKUP(A2,INDIRECT("["&GetFileNamefromCode("wbAcctFees")&".xlsx]gen_rpt'!$A:$K"),11,)

    Please Login or Register  to view this content.
    Why its not working? and Whats the solution for this? Thanks in advance.

    Note:
    The workbook having the cell with the formula is having reference to the workbook having the variable wbAcctFees.

    Haven't got the answer over here:
    http://www.mrexcel.com/forum/excel-q...name-code.html

  2. #2
    Registered User
    Join Date
    01-12-2015
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    16

    Re: How to evaluate an workbook object by its name in code?

    shouldn't you have a identifier for the workbook and/or sheet you're trying to open?

    Please Login or Register  to view this content.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,734

    Re: How to evaluate an workbook object by its name in code?

    The OP wants to be able to pass in a variable name as a string (not the variable or its value) and then have the code take that variable name and then determine the value of that variable dynamically. However, that is not how Evaluate works, and there is not another built-in way to do this. A different approach is needed. There is further discussion at the cross-post linked above.

    Evaluate does things like if you use the expression

    Evaluate("A1")

    it will return a Range object for the range A1.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    06-28-2011
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: How to evaluate an workbook object by its name in code?

    Quote Originally Posted by 6StringJazzer View Post
    The OP wants to be able to pass in a variable name as a string (not the variable or its value) and then have the code take that variable name and then determine the value of that variable dynamically. However, that is not how Evaluate works, and there is not another built-in way to do this. A different approach is needed. There is further discussion at the cross-post linked above.

    Evaluate does things like if you use the expression

    Evaluate("A1")

    it will return a Range object for the range A1.
    Yes StringJazzy. That's exactly what I want to do? To change a single string into a code. No single line of code to do that? Let's forget the evaluate. I don't want to go with it as it wont change a string to any object other than the excel natives.

    there is not another built-in way to do this. A different approach is needed.
    Is learning the Dictionaries and Collections the only to achieve this? to change a string into a code
    There is further discussion at the cross-post linked above.
    Can someone please expalin how to achieve this by using defined names?

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,734

    Re: How to evaluate an workbook object by its name in code?

    When I see a question like this, asking for something very specific that is not supported by the language, I refocus on the overall problem you want to solve. I need we need to rethink the whole solution.

    You have a formula in a worksheet that refers to a workbook that was opened by VBA code. Do you have just one variable that refers to one workbook and one formula that needs it? If so then you don't even have to pass a variable to the code, you can just return the name of the workbook that was opened in Function Mac (by the way, I would make that Sub Mac because it doesn't return a value--a matter of programming style).

    The best way to get a solution for this is to describe your whole problem. Attaching a workbook would be even better.

+ 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. After Evaluate code jumps to end sub
    By BHudPE in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-24-2010, 02:33 PM
  2. Using EVALUATE code on >255 Strings
    By jamesryan in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-28-2010, 06:27 AM
  3. VBA evaluate code error
    By Dulanic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2010, 10:39 AM
  4. Trying to EVALUATE a cell in a different workbook
    By PingPing in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-24-2010, 11:07 AM
  5. When to Put Code in Workbook/Sheet Object
    By inwalkedbud in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2008, 12:35 AM

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