+ Reply to Thread
Results 1 to 2 of 2

Defining variables in Excel 2010

  1. #1
    Registered User
    Join Date
    10-05-2013
    Location
    The Toon
    MS-Off Ver
    Excel 2010
    Posts
    7

    Defining variables in Excel 2010

    Just need direction on this please...

    Where should I define variables if I want these to be available to all modules (and ThisWorkbook)? I assumed this would be in the Option Explicit declaration section of the module that the variable is first used and preceded by the Public statement.

    I lose the variable's scope (reset?) executing the first line of the following code (in ThisWorkbook), to which I wish to add files to an Outlook email which has these variable names.

    Please Login or Register  to view this content.
    Regards.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Defining variables in Excel 2010

    Hi stattouk,

    Where should I define variables if I want these to be available to all modules (and ThisWorkbook)?
    The easiest way to do what you want is to declare the variables in any Ordinary Code Module after the 'Option Explicit' statement and before the first Macro in that module. DO NOT declare the variables in a Sheet Code Module or the ThisWorkbook Code module (because they are 'Class Modules' which behave in a slightly different manner).

    See the bottom of the following link for more information about the scope of variables in general: http://www.functionx.com/vbaexcel/Lesson03.htm

    For example:
    Please Login or Register  to view this content.
    Lewis

+ 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. Defining variables in VBA
    By beni12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-26-2011, 03:01 PM
  2. defining the variables as values
    By sportsranker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-16-2009, 05:00 PM
  3. Defining cells as variables (To be used for copying)
    By PaulEku in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2008, 03:17 PM
  4. Using Variables when defining named ranges
    By jerryliang2k in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-23-2008, 05:01 PM
  5. Problem defining -some- variables in an IF statement
    By Gordon@work in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2007, 02:51 AM
  6. VBA defining variables
    By Jeff in forum Excel General
    Replies: 2
    Last Post: 11-03-2005, 07:40 PM
  7. solver and defining all variables different than one another
    By excel_excel_excel in forum Excel General
    Replies: 0
    Last Post: 07-19-2005, 03:05 AM

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