【问题标题】:VBA - Relative vs Absolute References to XLAM filesVBA - 对 XLAM 文件的相对引用和绝对引用
【发布时间】:2014-08-06 09:02:48
【问题描述】:

我的同事开发了一个包含在 xslm 文件中的应用程序,我也必须可以访问该文件。该文件连接到许多 xlam 库,由于速度原因,这些库本地保存在他的机器上(从共享驱动器加载 30 个库需要很长时间)。

为了让我访问此应用程序,在共享驱动器上创建了一个副本,其中库也被复制了。当我的同事打开另一个应用程序(引用他的本地 xlam 库),然后在 Excel 的一个实例中打开共享 xlsm 文件时,共享文件中的引用会从共享 xlams 转移到本地 xlams,从而使共享应用程序无法正常工作我 - 我无法访问他的本地 xlams。可以禁止这种自动更改 xlam 引用吗?有没有办法像在 VBA 中引用 DLL 一样对 xlam 引用的路径进行硬编码?

非常感谢任何帮助, 丹尼尔

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    这些 xlam 文件是插件。

    您应该能够在运行时使用路径引用它们。这是我在MSDN Blog: Accelerating Things (Loading Excel Add-Ins at Runtime) 上为您找到的示例(您可以通过 Google 搜索找到此示例)

    Private Sub Workbook_Open()
        call LoadExternalAddIns
    End Sub
    
    Private sub LoadExternalAddIns(optional byval sAddinName as string="")
    
        Dim success As Boolean
        Dim myAddIn As AddIn
        dim sPath2AddIn as string
        'dim sAddinName as string
    
        sPath2AddIn = "c:\myaddins\"
        if sAddinName="" then sAddinName="myxlam.xlam"
    
        ' Load XLL
        'success = Application.RegisterXLL(sPath2AddIn & sAddinName)
    
        ' Load and install new XLAM
        Set myAddIn = Application.AddIns.Add(sPath2AddIn & sAddinName)
        myAddIn.Installed = True
    
        ' Load known XLAM
        For Each myAddIn In AddIns
            If myAddIn.Name = "myknownaddin.xlam" Then
                myAddIn.Installed = False
                myAddIn.Installed = True
            End If
        Next    
    End Sub
    

    当然,这只是一个让您入门的示例,事实上,由于您有很多外接程序,您可能希望将它们列在隐藏工作表上,然后调用上述过程 LoadExternalAddIns 可能会在循环中传递每个人的名称,例如 call LoadExternalAddIns (sAddInName)。

    更多资源:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-20
      • 2015-02-15
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多