+ Reply to Thread
Results 1 to 15 of 15

VBA References

Hybrid View

  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,481

    re: VBA References

    Msgbox "Program version " & Val(Application.Version)
    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":

     Dim olApp As Object
     Set olApp = CreateObject("Outlook.Application")
    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
    2010, 2019
    Posts
    40,689

    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,259

    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.
    'Written: February 04, 2009
    'Author:  Leith Ross
    'Summary: Automatically loads the correct Outlook library
    '         and sets a reference to it in the Visual Basic Editor
    
    Sub LoadOutlookLibrary()
    
      Dim olPath As String
      Dim WSH As Object
      
        Set WSH = CreateObject("WScript.Shell")
        
          olVersion = WSH.RegRead("HKCR\Outlook.Application\")
          
            Select Case olVersion
              Case "Microsoft Outlook 8.0 Object Library"
                ObjLib = "msoutl8.olb"
              Case "Microsoft Outlook 98 Object Library"
                ObjLib = "msoutl85.olb"
              Case "Microsoft Outlook 9.0 Object Library"
                ObjLib = "msoutl9.olb"
              Case "Microsoft Outlook 10.0 Object Library", "Microsoft Outlook 11.0 Object Library"
                ObjLib = "msoutl.olb"
            End Select
             
          olPath = Split(Environ("Path"), ";")(0) & "\"
          
          On Error Resume Next
          Application.VBE.ActiveVBProject.References.AddFromFile olPath & ObjLib
        
        Set WSH = Nothing
        
    End Sub
    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 Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,705

    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