+ Reply to Thread
Results 1 to 12 of 12

using an add-in to store constants

  1. #1
    Registered User
    Join Date
    11-02-2013
    Location
    ajax
    MS-Off Ver
    Excel 2010
    Posts
    32

    using an add-in to store constants

    Can I use an add in to store a constant. I want to use that addin so all my workbooks can reference to certain constants.

    Moderator's Note: Modified the thread title to correct a typo --6SJ
    Last edited by 6StringJazzer; 11-03-2013 at 10:07 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,924

    Re: using an add in to score constants

    I'm not proficient in using named constants, so I'm not certain how well it would work to define a named constant to be used in any open workbook.

    The strategy I use for frequently used constants looks something like this:

    1) I have an add-in file that contains multiple user-defined VBA functions (UDF's).
    2) For constants that I want available across all workbooks, I store a UDF for this purpose (these are the simplest UDF that one can write) in this add-in. For example, I have a UDF for the gas constant that I use that will look something like this
    Please Login or Register  to view this content.
    which I can call from any open workbook, just like the PI() function =Rgas()
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    11-02-2013
    Location
    ajax
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: using an add in to score constants

    Do i put that code in the addin file or the workbook that i want to use the constant. What I am trying to do is have a place to store my constants (named cell) that can be referenced by several workbooks that use the same constant. When ever I have to update that constant, the change can be made in one place.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,924

    Re: using an add in to score constants

    I'm a little confused. Do you have the constants stored in a workbook and want to use named cells to refer to them? As I said, I'm not very conversant with named ranges -- especially how to reference them across workbooks like that. If that is the approach you want to take, you will probably store them in your "personal.xlsx" file and someone else can help you reference them from other workbooks.

    Using a UDF like I proposed, you store the UDF in an add-in file. Once the add-in is "installed" (through the manage add-ins dialog), the UDF's are available to all open workbooks and can be used like Excel's built in functions (like the =PI() function). As in my example, I have found it easiest to store the value of the constant in the function code rather than in a spreadsheet cell.

  5. #5
    Registered User
    Join Date
    11-02-2013
    Location
    ajax
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: using an add in to score constants

    I like your recommendation, just one question though. Do I enter this code into the addin and does it go into a module or a class module. Can you please write an example for the following: I have 5 workbooks that use a constant named "volume" which = 39.678. I want to store this constant in an add in. That way when this number needs to updated every month i only have to do it in the addin,

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,924

    Re: using an add-in to store constants

    I have never used a class module, so I can't see that it would "need" to go in a class module.

    So, the "constant function" goes in a regular module in a workbook that you save as an add-in. Once the add-in is saved, you install the add-in from the manage add-ins dialog (you will probably have to use the Browse button to locate the add-in the first time).

    The code itself should be as simple as the one I posted above:
    Please Login or Register  to view this content.
    Is there a specific step in this process that you are having difficulty with? I'm not in a position right now to create the add-in for you, but if you explain exactly where in this process you are stuck, we should be able to help you.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: using an add-in to store constants

    I have 5 workbooks that use a constant named "volume" which = 39.678. I want to store this constant in an add in. That way when this number needs to updated every month i only have to do it in the addin,
    Then all the workbooks that use some prior value of 'volume' will change when reopened.

    That's a variable, not a constant.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    11-02-2013
    Location
    ajax
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: using an add-in to store constants

    > Ok, here is what I have done. I added this code to my add-in:
    > Function volume() As Double
    > volume = 39.677
    > End Function
    >
    > On my new open workbook I type in =volume and the cell returns a value
    > #NAME?
    >
    > What am I doing wrong?

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,924

    Re: using an add-in to store constants

    As with the built in PI() function, the parentheses are required, even though no arguments are being passed to the function.

    Did you install and activate the add-in? http://office.microsoft.com/en-us/ex...658.aspx?CTT=1 Does the add-in file appear in your list of available add-ins? Does the function appear in the function wizard under the "user-defined" category?

    Beyond that, the name error means that Excel is somehow not recognizing the function name. An error in typing the function or an error in installing the add-in are the most common errors I've come across for this.

  10. #10
    Registered User
    Join Date
    11-02-2013
    Location
    ajax
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: using an add-in to store constants

    Do you mean I have to type in =volume()

  11. #11
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,924

    Re: using an add-in to store constants

    Yes. (additional text to bring message to 10+ characters)

  12. #12
    Registered User
    Join Date
    11-02-2013
    Location
    ajax
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: using an add-in to store constants

    Thank you it works! Your help is much appreciated.

+ 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. Moving a calclated score to a master score sheet and ranking the scores into placings
    By Jongleur69 in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 04-22-2013, 11:53 PM
  2. Replies: 2
    Last Post: 03-20-2012, 06:30 PM
  3. Counting constants between constants
    By po07pro in forum Excel General
    Replies: 2
    Last Post: 10-13-2011, 06:02 AM
  4. Pulling test score based on date, not highest score.
    By PowerSchoolDude in forum Excel General
    Replies: 2
    Last Post: 12-01-2009, 06:42 PM
  5. formula to work out score based on score system
    By Nathaniel82 in forum Excel General
    Replies: 5
    Last Post: 08-10-2009, 11:25 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