Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90189

Accounting references in VBA for different versions of office

$
0
0

If users are on 64bit Office with Office 16 the below code works fine but how do I account for users on different versions and 32bit also?

Sub Add_References_Programmatically()
Dim VBAEditor       As Object
Dim vbProj          As Object
Dim chkRef          As Object

Set VBAEditor = Application.VBE
Set vbProj = ActivePresentation.VBProject

On Error Resume Next
    vbProj.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 0
On Error GoTo 0

For Each chkRef In vbProj.References
    If chkRef.Name = "Excel" Then
        GoTo CleanUp
    End If
Next chkRef

vbProj.References.AddFromFile "C:\Program Files\Microsoft Office\Root\Office16\EXCEL.EXE"

CleanUp:
Set vbProj = Nothing
Set VBAEditor = Nothing
End Sub

Viewing all articles
Browse latest Browse all 90189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>