Add references programmatically

后端 未结 4 1947
长情又很酷
长情又很酷 2020-12-09 19:45

we have an Access-Application which does not work on some clients, mainly because references are broken. That happens for example when you start the access application with

4条回答
  •  粉色の甜心
    2020-12-09 20:16

    So yeah, this answer is a bit late, but just in case someone stumbles across this like I did looking for an answer, I figured out the following bit of code to add an excel reference and it seems to work fine, also in MDE/ACCDE!

    If Dir("C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.exe") <> "" And Not refExists("excel") Then
        Access.References.AddFromFile ("C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.exe")
    End If
    If Dir("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe") <> "" And Not refExists("excel") Then
        Access.References.AddFromFile ("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe")
    End If
    If Dir("C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.exe") = "" And Dir("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe") = "" Then
        MsgBox ("ERROR: Excel not found")
    End If
    

    And the refExists references the following function:

    Private Function refExists(naam As String)
    Dim ref As Reference
    refExists = False
    For Each ref In References
        If ref.Name = naam Then
            refExists = True
        End If
    Next
    End Function
    

提交回复
热议问题