excel - 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))
错误出现在最后一行
解决方案
为了防止这种情况,请使用后期绑定而不是早期绑定。
看 …
在后期装订中,您将使用
Set oAPP = CreateObject("Outlook.Application")
创建 Outlook 实例(无需设置对库的引用),而早期绑定将使用Set oAPP = New Outlook.Application
并且需要该引用。
因此,如果您使用不同版本的 Outlook,建议使用后期绑定来防止这些奇怪的行为。请注意,您将失去智能感知,而不是声明Dim oAPP As Outlook.Application
需要Object
用于所有 Outlook 特定类型的特定类型:Dim oAPP As Object
推荐阅读
- reactjs - 你如何对反应引导列进行数字排序
- python - 仅当无法使用“with __ as”在 Python 中打开和读取新文件时才创建新文件
- python-3.x - 如何在python中重定向导入
- excel - 比较两个过滤列?
- ios - React Native 0.60.5 中没有链接模块
- azure - 将 ADF 用于 REST API
- amazon-web-services - lambda 添加权限 - S3 存储桶的账户 ID
- javascript - 在 Angular 中使用来自服务器的数据修补 FormArrays 值的问题
- python-3.x - AttributeError:模块“tensorflow”没有属性“get_default_graph”。向模型添加新层时出现此错误
- c# - 使用 .NET 从另一个 XML 文件附加一个 XML 节点