+ Reply to Thread
Results 1 to 4 of 4

Setting Global Variables

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Setting Global Variables

    I am trying to seta variable in one workbook, to then pass it to another workbook.

    In workbook A, I have this code:

        Dim Target, Test_Emp, Test_Row
        Dim TestModel, TargetBook
        
        
        Sheets("testing_menu").Select
        Target = Range("test_target")
        Test_Emp = Range("A15")
        TestModel = ActiveWorkbook.Name
        
    'Other code running here
    '.....
    
        Application.Run ("'" & Target & "'!Queries_3")

    The last line runs a macro called Queries_3 in workbook B.

    I am trying to pass a global variable, from workbook A to workbook B, but have exhausted my googling.

    Any help would be really really great!.

    Thanks

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Setting Global Variables

    Hi,
    Does Queries_3 take an argument, or does it need to refer to a variable in workbook B? If it's the latter, you would have to either make the variable a member of the ThisWorkbook module of workbook B, or add a routine to workbook B that takes an argument and assigns it to the variable in the other workbook.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Re: Setting Global Variables

    Hi xlnitwit

    At the moment, it does not have an argument, (If workbook B (abc) = variable then), I assume that's what you meant.
    How would I go about doing this?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Setting Global Variables

    If you amend Queries_3 to take an argument, you can simply pass the value directly in the Run statement, rather than relying on public variables.

+ 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] Global variables?
    By RustyNail in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-01-2018, 02:48 PM
  2. [SOLVED] Setting a Global Variable
    By manofcheese in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-12-2014, 12:24 PM
  3. Setting Global Variables from UserForm
    By vikasnitk85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-13-2012, 11:04 AM
  4. Global Variables
    By Slyone2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2010, 12:20 PM
  5. Setting Global Recal
    By nils.soderstrom in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-03-2010, 07:32 AM
  6. Setting a Global Variable
    By ChemistB in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-29-2008, 10:51 AM
  7. Global Variables
    By mattsvai in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2006, 01:10 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