使用VBA代码(宏)连接引用(工具>引用) [英] Connect references (Tools>References) with VBA code (macros)
问题描述
我想使用VBA代码以编程方式将一些引用连接到我的VBA项目,即不使用工具">引用"手动设置引用.这可能吗?例如Microsoft Office 12.0对象库.
I want to programmatically connect some references to my VBA project using VBA code, i.e. without manually setting references using Tools>References. Is this possible? For example Microsoft office 12.0 Object library.
推荐答案
您没有提到Office应用程序.在MS Access中,您可以使用:
You do not mention an Office application. In MS Access, you can use:
ReferenceFromFile "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSO.DLL"
也就是说,提供您要添加的参考的完整路径.
That is, give the full path for the reference you wish to add.
来自: http://wiki.lessthandot.com/index.php/添加,删除,_检查参考
类似地,在Excel中:
Similarly, in Excel:
ActiveWorkbook.VBProject.References.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSO.DLL"
要在Excel中列出引用,请执行以下操作:昏暗参照作为参考
To list references in Excel: Dim ref As Reference
For Each ref In ActiveWorkbook.VBProject.References
Debug.Print ref.Description; " -- "; ref.FullPath
Next
这将在我的机器上的特定工作簿上返回以下内容:
This returns the following on my machine on one particular workbook:
Visual Basic For Applications -- C:\PROGRA~1\COMMON~1\MICROS~1\VBA\VBA7\VBE7.DLL
Microsoft Excel 14.0 Object Library -- C:\Program Files\Microsoft Office\Office14\EXCEL.EXE
OLE Automation -- C:\Windows\system32\stdole2.tlb
Microsoft Forms 2.0 Object Library -- C:\Windows\system32\FM20.DLL
Microsoft ActiveX Data Objects 6.0 Library -- C:\Program Files\Common Files\System\ado\msado15.dll
Microsoft XML, v6.0 -- C:\Windows\System32\msxml6.dll
Microsoft Office 14.0 Access database engine Object Library -- C:\Program Files\Common Files\Microsoft Shared\OFFICE14\ACEDAO.DLL
Microsoft Visual Basic for Applications Extensibility 5.3 -- C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB
Microsoft Office 14.0 Object Library -- C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSO.DLL
这篇关于使用VBA代码(宏)连接引用(工具>引用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!