+ Reply to Thread
Results 1 to 10 of 10

Adding references from within VBA code

  1. #1
    Forum Contributor
    Join Date
    08-14-2008
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    103

    Adding references from within VBA code

    Hi all,

    I have a workbook that has a wee bit of code which makes an Access Table from within excel. It requires a reference to the Microsoft DAO 3.6 Object Library, and to date I have just selected it from the Tools menu in the VBA editor as needed.

    I would like to give this workbook to some coworkers who are not familiar with macros. Is there a line or two of code which checks to see if this library is referenced, and if not adds it?

    Thanks and have a good ANZAC weekend
    Last edited by HammerTime; 04-26-2010 at 07:54 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Adding references from within VBA code

    Hello HammerTime,

    Here is a macro to add the reference.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    08-14-2008
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    103

    Re: Adding references from within VBA code

    Awesome! Thanks Leith

  4. #4
    Forum Contributor
    Join Date
    08-14-2008
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    103

    Re: Adding references from within VBA code

    oops! Actually it gives me the following error:

    "VBE Object library not loaded
    Object library no registered"

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Adding references from within VBA code

    Hello HammerTime,

    Check your reference in the VBE and see if the library is there. If version numbers are different that will cause an error. This can be a potential problem with other computers if those computers are not using the same version of Office as you.

  6. #6
    Forum Contributor
    Join Date
    08-14-2008
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    103

    Re: Adding references from within VBA code

    It appears to be there!

    I just noticed that you have "Visual" in the title. Mine is simply "Microsoft DAO 3.6 Object Library", are these different?

    Also, where can I find that long reference number? (in case I want to change the code to add a different ref.)

    Also, we have a common excel install in all computers, so the document will be shared with people that (should) have an identical set up as me.

    Thanks again for the help :D
    Attached Images Attached Images

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Adding references from within VBA code

    Hello HammerTime,

    Fooled again by Microsoft. It isn't a standard type library but a DLL. Requires a slightly different loading method. Working on an update.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Adding references from within VBA code

    Hello HammerTime,

    I am stumped. I can't load it from VBA even if I register the dll before setting the VBE reference. I have done this successfully with other modules in the past. Perhaps someone else knows the answer.

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding references from within VBA code

    Once you add a Reference manually & save the workbook the reference remains when the workbook is distributed.The only problem would be if the dll is missing from the other computer
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  10. #10
    Forum Contributor
    Join Date
    08-14-2008
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    103

    Re: Adding references from within VBA code

    Ok thanks Roy,
    I'll do some tests on a few computer around the office

+ 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