gpt4 book ai didi

excel - 如何从工具 --> 引用中自动检查 'Microsoft ActiveX Data Objects x.x Library'?

转载 作者:行者123 更新时间:2023-12-04 21:05:23 30 4
gpt4 key购买 nike

我们与客户共享我们的 Excel 宏 - MS Access 项目。

他们不知道从工具 --> 引用中选择“Microsoft ActiveX 数据对象 x.x 库”。

任何自动更新 MS ADO 库设置的代码?

注意:在 Office 中,我们使用的是 MS 2010。我认为客户的办公室使用的是 Micorsoft XP。

最佳答案

我在上面建议使用后期绑定(bind),但你可以这样做(我的代码与 PPT 2010 中使用的完全一样,应该很容易适应 Access,但我从不使用 Access)。

您可能需要更改 ADODBReference在 XP 中使用的常量。或者您可以添加另一个常量和逻辑检查以查看 Application.Version并从适当的目标路径加载。

Public Const ADODBReference As String = "C:\Program Files (x86)\Common Files\System\ado\msado15.dll"

Sub PPT_AddRefToADODBLibrary()
'Adds a programmatic reference to ADODB library if one doesn't already exist
'ADODBReference is a public const refers to Microsoft ActiveX Data Objects 6.0 Library

If Not PPT_RefExists(ADODBReference, "Microsoft ActiveX Data Objects 6.0 Library") Then
Application.VBE.ActiveVBProject.References.AddFromFile _
ADODBReference
Else:
'Already installed
End If

End Sub

上面的 sub 调用了这个自定义函数,它首先迭代事件的引用
Function PPT_RefExists(refPath As String, refDescrip As String) As Boolean
'Returns true/false if a specified reference exists, based on LIKE comparison
' to reference.description.
Dim ref As Variant
Dim bExists As Boolean

'Assume the reference doesn't exist
bExists = False

For Each ref In Application.VBE.ActiveVBProject.References
If ref.Description Like refDescrip Then
PPT_RefExists = True
Exit Function
End If
Next
PPT_RefExists = bExists
End Function

关于excel - 如何从工具 --> 引用中自动检查 'Microsoft ActiveX Data Objects x.x Library'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22766972/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com