+ Reply to Thread
Results 1 to 5 of 5

How to set a variable based on a cell value that is in another not opened excel workbook?

  1. #1
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    How to set a variable based on a cell value that is in another not opened excel workbook?

    Hi all,

    my question is very simple. I am a vba beginner and I am having difficulties in some aspects of vba. My problem is how to set a variable based on a cell value that is in an external excel workbook that is also closed.

    The code i wrote is this:

    Please Login or Register  to view this content.
    This code works but what extension do i write before the variable "one" and variable "two" if they are in an external file?
    Say the location of the workbook is in C:\Users\Kevin\Google Drive\Pricelist\xyz.xlsm and in Sheet1 of xyz.xlsm. How do I get the value of Cell A1 and Cell B2 in that target location?

    Im guessing something like:

    Please Login or Register  to view this content.
    something like that?

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: How to set a variable based on a cell value that is in another not opened excel workbo

    Try this,

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: How to set a variable based on a cell value that is in another not opened excel workbo

    Hi Japan Dave,

    Your code works but my problem is that i don't want the workbook xyz.xlsm to be opened. I want it to work just in the same way a formula in another workbook (Book1) can call up data from xyz.xlsm by putting ='C:\Users\Kevin\Google Drive\Pricelist\[xyz.xlsm]Sheet1'!$A$1 in a cell in Book1 without opening xyz.xlsm. The reason being is that the xyz.xlsm contains confidential data that i dont want them to see. Plus xyx.xlsm has welcome messages and some macros set in workbook_open that will make it really not feasible.

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: How to set a variable based on a cell value that is in another not opened excel workbo

    The only way you are going to achieve that is if you link the workbooks via formula and having the data in the workbook that you are running the macro in. Maybe have it on a not visible sheet? You can't do what you are suggesting within code.

    Or you could do something like this below which will disable any macros in the other workbook and if there is an error always have the workbook close so that the staff can't see it.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to set a variable based on a cell value that is in another not opened excel workbo

    Assuming the sheet name is "Sheet1"
    Please Login or Register  to view this content.
    Last edited by jindon; 04-21-2013 at 11:16 PM.

+ 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