MISSING: Microsoft Outlook XX.X Object Library

EAnton781

New Member
Joined
Feb 5, 2009
Messages
39
Hi Everyone,

I have some code in my Excel 2003 document to generate an email message. It references the Microsoft Office 11.0 Object Library.

Problem is, some employees do not have 11.0, they have the 10.0 Object Library. Both 11.0 and 10.0 refer to a file named MSOUTL.OLB

I'm trying to write some code to identify this issue and update the reference selection as needed when the workbook is opened but have had no luck.

My latest attempt is as follows:
Code:
   Dim vbProj As VBProject ' This refers to your VBA project.
   Dim chkRef As Reference ' A reference.
   Dim RefGUID As String
   Dim refPath As String
   ' Refer to the activedocument's VBA project.
   Set vbProj = ActiveWorkbook.VBProject
   ' Check through the selected references in the References dialog box.
   For Each chkRef In vbProj.References
      ' If the reference is broken, send the name to the Immediate Window.
      If chkRef.IsBroken Then
        RefGUID = chkRef.Guid
        refPath = chkRef.FullPath
        vbProj.References.Remove chkRef
        vbProj.References.AddFromGuid RefGUID, 0, 0
      End If
   Next

This code finds a missing reference, clears it, and then attempts to relocate the file based on the registry GUID. The problem is that it even though the file is MSOUT.OLB, it is still looking for a 11.0 version instead of accepting the 10.0 version.

Any thoughts would be much appreciated!

P.S. Yes, i've tried late-binding here, but we are using .UserProperties to embed hidden variables in the email message which we can't get to work without using the object reference.
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
I cannot, but other than the help file, I would search MSDN.

Norie may well show a better way, but in general, I find it easiest to write the code early bound (intellisense just makes things so much easier), then when all happy and warm and fuzzy that no smoke pours out of the PC when I run the code, I go back and 'fix' Constants and such.

Once you've done it a couple of times, you'll start catching where you need to do this as you write. While in early bound, right-click on the constants and get quick info.

I would also suggest looking at Enum. This way you can name constants same/similar, which keeps the code intuitive (ie - your eyes don't bleed when reading/editing/updating several months later) and still allows late bound.

Hope that helps,

Mark
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,056
Office Version
  1. 365
Platform
  1. Windows
EAnton

I've got to agree with Mark - develop using early binding and once you have everything working convert to late binding.

One of the main advantages of doing thing's this way is that, as Mark mentions, you have access to Intellisense and you can also use the Object Browser.

I actually used the Object Browser in Outlook VBA to find out more information about UserProperties.

It's not something I've ever used, but then I've never really automated Outlook/email much.:)

You could replace olText with 1 or you could add a declaration like this and then use that in your code.
Code:
Const olText = 1
 

Watch MrExcel Video

Forum statistics

Threads
1,118,311
Messages
5,571,495
Members
412,397
Latest member
Phillip Rogers
Top