Consulting

Results 1 to 6 of 6

Thread: add/fix vba reference

  1. #1
    VBAX Newbie
    Joined
    Oct 2009
    Posts
    4
    Location

    add/fix vba reference

    Hi,
    trying to fix library ref error with vba.
    code won't run as long as there is a "missing" reference.
    using code "addreference()" from this site.

    need to turn something off so that on open
    the code will run, find the offending missing library
    delete the reference to the library
    add the reference to the good lib
    and continue.

    otherwise user has to go to vba and fix manually.

    and way this can be done???

    thanks

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    No. That is why some just use late bound objects. It is best to figure out which one is causing the problem and then use the late bound method, when possible.

  3. #3
    VBAX Newbie
    Joined
    Oct 2009
    Posts
    4
    Location
    Hi,
    thanks for the quick reply.

    the user is using excel 7, the new code is 13. The reference is to outlook 15 which needs to be changed to outlook 12 for this user.
    don't know how to do this with "late bound method".

    peter

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You can look at some MVP sites for some examples.

    I like Ron de Bruin's since this is an Excel forum. http://www.rondebruin.nl/win/s1/outlook/mail.htm

    See the bottom of his link below there where his previous code uses CreateObject("Outlook.Application") for the late bound method and early bound with the needed reference example at the end. Note that late bound used Dim somevariable as Object whereas early bound Dims must use the proper object dimensional types.

    http://www.rondebruin.nl/win/s1/outlook/signature.htm

  5. #5
    VBAX Newbie
    Joined
    Oct 2009
    Posts
    4
    Location
    thank you so much
    if i understand correctly...
    with late binding your code doesn't rely on the reference in tools. so uncheck the box and let the code do the work.

    thanks again
    peter
    (makes you wonder why the code I was using was ever posted if it couldn't work???)

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    No, there is more to it than just removing a reference. What some do is to code using early bound methods but make the production version late bound.

    See the links here if you want to learn more. http://lmgtfy.com/?q=vba+late+binding+vs+early+binding

    Here is a quick example where I show how to use the Scripting.FileSystemObject early bound method method and the late bound method is commented out.
    Sub CopyFileToDir(filespec, Destination)    
        'Late bound
        'dim fs as Object
        'Set fs = CreateObject("Scripting.FileSystemObject")
        
        'Early bound
        'Needs Reference: MicroSoft Script Runtime, scrrun.dll
        'Instructions: http://support.microsoft.com/default.aspx?scid=kb;en-us;186118
        Dim fs As Scripting.FileSystemObject
        Set fs = New FileSystemObject
        
        
        fs.CopyFolder ThisWorkbook.path, "t:\", True
        fs.CopyFile filespec, Destination
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •