PDA

View Full Version : Early vs. Late Binding



pooldead
04-16-2020, 07:26 AM
I have an Excel workbook that I created using the client-side Office 365 suite. Some of my users are getting an error "Can't find project or Library" when using macros. I've determined it's due to a missing reference to the MSOUTL.lib file, however because they are using Office 2013, they don't have the Office16 folder where the more recent version of this file resides. I don't have the power to update their software, so I'm looking into ways of making my workbook backward compatible. I came across Early Binding and Late Binding and have been researching both, but I'm having trouble understanding how and when to use each. Could someone provide some guidance here?

pooldead
04-16-2020, 07:48 AM
I did see the pinned thread about this error, however those steps did not work. The referenced website link is no longer found, and I don't want to just remove the reference, because the macro my users click creates an email that is necessary to the process. So I do need to find a way of keeping the reference to Outlook 16.0 library.

paulked
04-16-2020, 07:55 AM
If it's email you're having problems with then Ron de Bruin covers late binding here (https://www.rondebruin.nl/win/s1/outlook/amail7.htm).

Extract:

Early Binding

If you want to use the Intellisense help showing you the properties and methods of the objects as you
type you can use Early Binding. Bit faster also when you run your code but you can have problems when you distribute your workbooks. Excel will automatic update the reference number to Outlook when you open your workbook in a higher version of Excel/Outlook but not update it when you open it in a lower version of Excel/Outlook. With Late Binding as I used in the macro examples you not have this problem.

Add a reference to the Microsoft Outlook Library in Excel

1) Go to the VBA editor with the shortcut Alt - F11
2) Click on Tools>References in the Menu bar
3) Place a Checkmark before Microsoft Outlook ? Object Library
Where ? is the Outlook version number

Then replace this three lines in the code

Dim OutApp As Object
Dim OutMail As Object

Set OutMail = OutApp.CreateItem(0)

With this three lines

Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem

Set OutMail = OutApp.CreateItem(olMailItem)

Bob Phillips
04-16-2020, 09:22 AM
Take a look at this

http://www.xldynamic.com/source/xld.EarlyLate.html

pooldead
04-16-2020, 10:35 AM
paulked - I updated that in my workbook and am having a user test now. If it works (which I expect it will), I'll come back and mark as solved. Thanks!

xld - Thanks for that link. That does help clear some things up in my head.