0

I created a program on my work computer which runs Microsoft Office 2016 however, my colleague cannot use the VBA program because it doesn't have the updated object library. Specifically, the Date and Left function prevent the program from working.

If they are running a 2010 version of Microsoft Office, is it possible to update their Object Libraries?

Nikolajs
  • 325
  • 1
  • 3
  • 17
  • 2
    You should not need to explicitly adjust the references when you're just using core excel functionality. If you go into Tools >> References in the VB editor on your colleague's PC are there items flagged as "missing"? BTW the "Left" is likely a red herring - I've seen that highlighted where the issue was something else entirely – Tim Williams Jul 12 '18 at 17:11
  • @TimWilliams Yes, the Microsoft Outlook Object library is flagged as missing. I don't see how this could affect Excel VBA object library? – Nikolajs Jul 12 '18 at 17:20
  • `VBA.Strings.Left` is an alias for the `_B_VAR_LEFT` internal function, defined in VBA7.DLL. It being unrecognized is a clear indication that something is effectively corrupted in the cached compiled p-code in your VBA project; one way to reset this cache is to export/remove all modules and re-import them back in, [as TinMan suggested](https://stackoverflow.com/a/51311484/1188513). Unrelated, `_B_STR_LEFT` is aliased by the `VBA.Strings.Left$` function, which takes an actual `String` and returns an actual `String`, whereas `Left` takes and returns a `Variant`; you want `Left$`, not `Left`. – Mathieu Guindon Jul 12 '18 at 17:58
  • Please add the outlook reference hint to your question. TinMan wrote an answer (you've seen it?) that was not wrong but didn't cover your needs. With this information he would have avoid the effort. – ComputerVersteher Jul 12 '18 at 19:59

1 Answers1

1

You can't use references to newer libary version using an older version as it can provide functions that the older version don't have, just the other way around it could work (old reference with new libary as they are usually backward compatible).

If one reference is broken, all other are not loaded too. That's why the VBA functions Date and Left fail as the libary is not loaded.

To get independent of the Office version use Late-Binding, but even then you can't use new functions on old versions (just use the subset of the oldest version you want to support or check for version and if the it is too old display a message that the faeture that uses the function is not availible for this Office version).

You can develop Early-Bound to have Intellisense and object browser and switch to Late-Bound before distributing.

  • Remove the reference(s) in VBA -> Tools
  • Change class declarations to Object
  • Create instance with CreateObject
  • Replace enums with your own enum, with their integer value or with a constant

Example:

Dim OutlookInstance as Outlook.Application
Dim OlMailItem as Outlook.Mailitem

Set OutlookInstance = New Outlook.Application
Set OlMailItem = OutlookInstance.CreateItem(olMailItem)

changes to:

Dim OutlookInstance as Object
Dim OlMailItem as Object

Set OutlookInstance = CreateObject("Outlook.Application")
Set OlMailItem = OutlookInstance.CreateItem(0)

You can download a module with enums for Outlook 2013 at Codekabinet (not tested, but they should cover most of Outlook 2016) and import to your project or get the values while you are Early-Bound from object-browser or just google.

ComputerVersteher
  • 2,638
  • 1
  • 10
  • 20