Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook Object Library Does Not Switch Between Versions 12 And 14

I have a .dotm template file on a network share. There are macros with references to the Word, Office, and Outlook object libraries. We use two different platforms, Windows XP and Windows 7, along with Microsoft Office 2007 and Office 2010. When users open the template file the references for Word and Office adjust automatic and accordingly (that is, they’re set to Microsoft Word 12 Object Library or Microsoft Word 14 Object Library as needed), and the macros run without a problem.

Microsoft Outlook Object Library switches properly from version 12 to 14. It does not switch properly from version 14 to 12. In that case, it gives the error that the libary is not found. Is this a bug? Is there a workaround? Something I’m overlooking?

like image 718
ForEachLoop Avatar asked Jun 25 '12 19:06

ForEachLoop


People also ask

How do I add a COM reference to Microsoft Excel 12.0 Object library?

Add an object library reference to your projectSelect the object library reference in the Available References box in the References dialog box and choose OK. Your Visual Basic project now has a reference to the application's object library.

How do I change References in VBA?

On the Tools menu, click References and then add a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 library. This library contains objects that refer to the VBA projects. Before you click OK, you must verify that the new reference is added above the "missing" reference.

How do I enable References in VBA?

Add A Reference Make sure that you click on the workbook you want to add the reference to, and from the VBA editor menu choose Tools -> References. In the displayed list check the box beside your renamed add-in, and then click on OK. You'll see that your workbook now has a new reference to the add-in.


1 Answers

ForEachLoop,

It appears that your question has largely been answered. I will merely add a bit of information for clarity's sake, and to provide this question with an answer. A user on the Microsoft Forums, Ossiemac, noted that LateBinding was the way to go, as has been stated by Siddarth Rout. As implied by Siddarth, that means you do not have to worry about references.

Ossiemac provided some sample code for using the LateBinding in the sending of an email, which I have reformatted and placed here:

Private Sub btnLateBindMethod_Click()
    ' Variables used for LateBinding
    Dim objOutlook As Object    'Outlook.Application  
    Dim objEmail As Object      'Outlook.MailItem     
    Dim objNameSpace As Object  'Outlook.NameSpace    
    Const OutLookMailItem As Long = 0    'For Late Binding
    Const OutLookFolderInbox As Long = 6 'For Late Binding
    Const OutLookFormatHTML As Long = 2  'For Late Binding
    Dim strSubject As String
    Dim strAddress As String


On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0     

    If objOutlook Is Nothing Then
        Set objOutlook = CreateObject("Outlook.Application")
        Set objNameSpace = objOutlook.GetNamespace("MAPI")
        objNameSpace.GetDefaultFolder(OutLookFolderInbox).Display
    End If

Set objEmail = objOutlook.CreateItem(OutLookMailItem)

strSubject = "Hello World"

    With objEmail

        '.To = strToAddress  'Commented to prevent accidental send

        .Subject = strSubject

        .BodyFormat = OutLookFormatHTML

        .Display

        'Full Name of window can change depending on Tools -> Options -> Mail Format
        'Changing this option for outgoing mail changes the window name.
        'However, AppActivate appears not to require entire name but needs up to end
        'of - Message which is included in heading following the Subject string
        'irrespective of the Mail Format option chosen.
        AppActivate (strSubject & " - Message")

    End With    
End Sub

Jimmy Pena has an article discussing the contrast of EarlyBinding and LateBinding -

~JOL

like image 156
DotNetDeveloper Avatar answered Sep 27 '22 20:09

DotNetDeveloper