+ Reply to Thread
Results 1 to 7 of 7

How to build a code library and include it in projects?

  1. #1
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    How to build a code library and include it in projects?

    How can I build a single code library to include in multiple projects?

    I have had a look on Google, but I am spending a surprisingly frustrating amount of time getting nowhere!!!!!!!

    In every other language that I've ever written code in, you can do this very simply.

    E.g. in PHP, you just do:

    PHP Code: 
    include_once ("mylibrary.php"); 
    I am assuming that I can write VBA code in a file that is not associated with a workbook, then somehow include that file in the projects of multiple workbooks.

    I am assuming that you can do this, because to not be able to do that, and to have to copy and paste your functions into every single new project that you wanted to create would be ... insane ... !!!!

    For that reason, I'm sure it's dead simple to do, I just haven't figured it out yet.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to build a code library and include it in projects?

    The google term that you are after is Add-In

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: How to build a code library and include it in projects?

    I am assuming that I can write VBA code in a file that is not associated with a workbook
    No you can't do that. The code resides within a workbook, whether that is the one being used or as Kyle suggested in a separate workbook saved as an add-in.

    You can export the code objects to text file but you can not then use them via an Include or Using type statement.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,864

    Re: How to build a code library and include it in projects?

    Are you thinking of something like this:

    http://www.rondebruin.nl/win/personal.htm
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: How to build a code library and include it in projects?

    Many thanks for your help so far ... I have much more understanding of how to do it now.

    I have decided to go down the Add-In route - it seems more intuitive to me (being used to writing code libraries in other languages) and it seems the most portable/deployable solution for my needs.

    My efforts so far:

    I have created a workbook to contain the library code, here: testlib.xlsm

    I have saved it as an XLAM file; Excel chose to save it in the default Add-Ins directory, namely as C:\Users\XmisterIS\AppData\Roaming\Microsoft\AddIns\testlib.xlam

    I am following the instructions here: http://www.cpearson.com/excel/createaddin.aspx

    But I have come to a stumbling block. The instructions state:

    "You can store the XLA file in any folder you want. The default location for add-ins is the folder named by the Application.UserLibraryPath property. The value will depend on your version of Excel and your version of Windows. On my Windows Vista Ultimate machine, that path, in both Excel 2003 and 2007, is

    C:\Users\Pearson\AppData\Roaming\Microsoft\AddIns

    If you save the XLA file in the Application.UserLibraryPath folder, Excel will automatically add the Add-In to the list of available Add-Ins displayed in the Add-Ins dialog box. If you save the XLA to another folder, you will need to click the Browse button in the Add-Ins dialog and navigate to your XLA file. In either case, you will need to check the box next to your add-in to open and load the Add-In."
    The problem is that (a) My add-in doesn't appear in the list of add-ins when I open excel. (b) Application.userLibraryPath does indeed point to where the add-in is saved. (c) I don't know where the "browse button in the add-ins dialog" is, and anyway, if I am reading the instructions correctly, then my add-in should automatically appear in the list of add-ins. But it doesn't. So I am doing something wrong ...

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How to build a code library and include it in projects?

    On Developer tab, click Add-ins button then Browse..., or from Excel Options you may click Manage Add-ins.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  7. #7
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: How to build a code library and include it in projects?

    Excellent! I got it, thanks to you guys.

    My HelloWorld function is now available for anything that wants to use it.

    Easy when you know how!!

+ 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. Need help with code that will build a URL
    By Habanero Time in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-17-2012, 10:10 PM
  2. RAND VBA code build on itself?
    By Rick-O-Shay in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-06-2011, 11:44 AM
  3. [SOLVED] Code Signing of Excel VBA projects
    By John Helmer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-26-2005, 04:05 PM
  4. [SOLVED] Excel VBA Projects & Visual Source Safe; WinAPI, Code Librarian.
    By Paul Martin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2005, 10:06 PM
  5. [SOLVED] Build in Code
    By B.G. in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-20-2005, 05:06 PM

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