+ Reply to Thread
Results 1 to 15 of 15

VBA References

  1. #1
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412

    VBA References

    Hi,

    To the best of my knowledge - different Office versions use different Outlook Library References.
    [9.0, 10.0, 11.0, 12.0]

    If I want to distribute a WB with some code that manipulates Outlooks Calendar - How do I:

    1) Determine, via code, the "Office" version of a particular computer ?
    2) How can I change/select the appropriate Outlook Reference via VBA ?

    *** Thanks in advance,

    Elm
    Last edited by ElmerS; 02-05-2009 at 10:52 AM.

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

    re: VBA References

    Please Login or Register  to view this content.
    You write your code using the oldest reference and then convert to late binding. This means you remove the reference to the library and change Outlook specific objects to generic Objects. Also you need to add you own outlook contants if used.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412

    re: VBA References

    Hi,

    If correctly understood your reply/command, - it displays the Office Version Number - BUT does not change the reference to the appropriate library.

    If this assumption is correct - I did find something - which I will have to check - and will appreciate if you will be kind to approve that I'm on the "right track":

    Please Login or Register  to view this content.
    Thanks, Elm
    Last edited by ElmerS; 02-04-2009 at 03:24 PM.

  4. #4
    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: VBA References

    You're on the right track.

    However, as Andy suggests, you should do your development using early binding, and switch to late binding when you're done, then do a regression test. That gives you IntelliSense while you're developing.

    You'll get compile errors for the Outlook constants when you switch over (because you're using Option Explicit), so you'll know what constants you need to define.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412

    re: VBA References

    Thank you too.

    Eventually, I wrote a piece of code with early Binding (before I knew what bindings mean).

    When I sent the WB to someone - who uses a different "Office" version - he got an error while running the code.

    I will try to merge the Late-Binding, in the code, and check the results on different versions.

    Elm.

  6. #6
    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: VBA References

    Hello ElmerS,

    Add this code to your macro. It will set a reference to the user's version of Outlook and allow you to early bind the object in the VBE.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 02-04-2009 at 05:08 PM. Reason: Updated code
    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!)

  7. #7
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412

    re: VBA References

    Thank you, Leith,

    I will keep your code for "emergency" purposes - meaning, in case no other, "shorter", solution will be found.

    However - :
    Why didn't you refer, in the code, to "Outlook 12.0 Object Library" !?

    Will be back to report.

    Elm
    Last edited by ElmerS; 02-04-2009 at 05:38 PM.

  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: VBA References

    Hello ElmerS,

    The reason Outlook 12.0 is missing is because I don't have Office 2007. Little difficult to verify the code if I don't have access to it. I revamped the macro to not use Environ("Path") as this not reliable. Also, I removed the Split function since this function was introduced in Office 2000. Use this code instead...
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412

    re: VBA References

    Hi, Leith

    I just checked, on another "Office 12.0" Computer and it uses the same "msoutl.olb" [as in 10.0 & 11.0].

    Thanks again, Elm

  10. #10
    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: VBA References

    Hello ElmerS,

    Thanks for passing that info along. I'll add it to the macro. Points to you for that.

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA References

    Leith, nice code... though I would suspect that on the file closing the reference needs to be removed else you have potential for MISSING references etc... so perhaps a little tweak such that the code can be invoked to add/remove the reference -- ie via Open/Close events ?

    Please Login or Register  to view this content.
    Thus the above could be invoked in both Open & BeforeClose events:

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412

    Re: VBA References

    Dear "Donkey",

    I removed the [SOLVED] sign before reading you post as I came cross this obstacle - you mentioned - about the need to remove the previous Reference - otherwise a [Missing] error is produced.

    I'm will check your suggestion within 10 minutes and come back to report.

    Thank you, Elm

  13. #13
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412

    Re: VBA References

    Quote Originally Posted by ElmerS View Post
    Dear "Donkey",

    I removed the [SOLVED] sign before reading you post as I came cross this obstacle - you mentioned - about the need to remove the previous Reference - otherwise a [Missing] error is produced.

    I'm will check your suggestion within 10 minutes and come back to report.

    Thank you, Elm
    ================ Added/Edited ==============

    Hip, Hip Hurray, Dear "Donkey", and a big applause to Leith.

    Everything works perfect.

    Thanks again, Elm

  14. #14
    Registered User
    Join Date
    07-22-2013
    Location
    CHENNAI
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: VBA References

    Dear Donkey / Elm / Leith,

    Thanks for the above code.

    I used the above code in office 2010. It runs fine. But when i run it in office 2007 it ended up with the "Compile Error: Can't find project or library".

    I have pasted the code below:

    Can you please help me overcome this issue as i need this one urgently.


    Thanks

    Ram.


    Please Login or Register  to view this content.

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

    Re: VBA References

    Welcome to the forum.

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    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

+ 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