+ Reply to Thread
Results 1 to 5 of 5

Passing Variables between Modules

  1. #1
    Registered User
    Join Date
    03-30-2007
    Posts
    5

    Question Passing Variables between Modules

    Does anyone know a way to pass variables between two modules?

    I've got code that is doing two separate things and now need to integrate them for more functionality. The easiest way for me to do this is by passing variables from one module to the other. I really don't want to copy and past the code into one module because I would like to keep them separate in case I need to reuse the code for another application.

    Thanks in advance.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good evening wombat7

    The easiest way is to "Dim" the variable before the top line of your code, then all the routines in that module would be able to access that variable.

    The code below uses this technique - run the macro "main" which will load myvar with a value - False and then pass this onto the test macro which it then calls.

    Please Login or Register  to view this content.
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    03-30-2007
    Posts
    5
    I've used Dim statements with many variables already, but it doesn't really help me in this case. I want to pass variables from one module to another (i.e. from Module 1 to Module 2), not between routines within a given module.

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try to use 'Global' or 'Public', for example:
    Module1:
    Please Login or Register  to view this content.
    Module2:
    Please Login or Register  to view this content.
    I hope it can help.

    Regards,
    Antonio

  5. #5
    Registered User
    Join Date
    03-30-2007
    Posts
    5
    Thanks!!!!!

+ 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