首页 > 解决方案 > Excel 365 正在替换 VBA 项目库

问题描述

我有一个 .xlsm 文件,其中包含使用一些项目库的宏,例如 Microsoft Outlook 14.0 库。该文件由用户更新并在他们之间交换。此文件是在装有 Office 2010 的 Windows 7 PC 上创建的。当在装有 Office 365 的 Windows 10 PC 上打开此文件时,项目库将被其较新版本(365 版本)替换。在此之后,当 Windows 7 + Office 2010 用户收到相同的文件并打开它时,宏不起作用,因为较新版本的库丢失了。

如何阻止 Office 365 替换库并确保宏在两台电脑上都能正常工作?Office 365 不应该自动向后兼容吗?

如果我理解正确,我已经在使用后期绑定:

'get user's email id
    Dim OutApp, olAllUsers, oExchUser, oentry, myitem As Object
    Dim User As String
    Set OutApp = CreateObject("outlook.application")
    Set olAllUsers = OutApp.Session.AddressLists.Item("All Users").AddressEntries
    User = OutApp.Session.CurrentUser.Name
    Set oentry = olAllUsers.Item(User)
    Set oExchUser = oentry.GetExchangeUser()
    user_email = LCase(CStr(oExchUser.PrimarySmtpAddress))

错误出现在最后一行

标签: excelvbaoffice365excel-2010

解决方案


为了防止这种情况,请使用后期绑定而不是早期绑定。

看 …

在后期装订中,您将使用

Set oAPP = CreateObject("Outlook.Application")

创建 Outlook 实例(无需设置对库的引用),而早期绑定将使用Set oAPP = New Outlook.Application并且需要该引用。

因此,如果您使用不同版本的 Outlook,建议使用后期绑定来防止这些奇怪的行为。请注意,您将失去智能感知,而不是声明Dim oAPP As Outlook.Application需要Object用于所有 Outlook 特定类型的特定类型:Dim oAPP As Object


推荐阅读