简体   繁体   中英

VBA reference changed version automatically

I wrote some VBA in Excel 2013 which references Outlook and is now used on a virtual machine. My laptop was upgraded to Office 2016 last week, I made some changes in this tool and then it failed to run on the VM.

Turns out the VBA Outlook reference in the file changed to v16.0 (Office 2016) and so when the VM tried to run the code (on 2013), it couldn't find this reference.

There was also the generic Office reference which stayed as v15.0 though.

I haven't been able to find any documentation on this - is this standard behaviour and if so, any ideas on how I can make further changes to this file without the reference messing up every time?

This is standard behaviour.

You need to move from Early to Late binding. Remove the Outlook reference in VBE and declare the outlook application as Object in code.

Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")

Bare in mind by doing so you will lose intellisense and you may have to change some constants to their numeric values, eg olMailItem to 0 .

Make sure you have Option Explicit at the very top of your module(s), as this will highlight compilation errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM