Introduction: I have a VBA application ~ 5000 lines that manipulates data in Excel, builds automatic charts and then exports the charts from each sheet to different PowerPoint Slides. This has been working fine for the past 5 months on many computers that are running this Code.
Problem: Some of the PCs in my organization have been upgraded from Office 2010 to Office 2013 and Office 2016. In my code I am using Early Binding on my PowerPoint handling, this is resulting in Errors since the References of the VB Project have changed from "Microsoft PowerPoint 14.0 Object Library" to "Microsoft PowerPoint 15.0 Object Library".
Target: how do I change the References automatically by code according to the PowerPoint version of the PC running my code ?
Status: My current code is able to loop through all enabled VBProject References, check if any of them is "Missing", and remove them to avoid the error message. I am also able to add PowerPoint 14.0 library by code.
My Question: how do I add the PowerPoint library according to the PowerPoint running on the PC of current user running this code, when PowerPoint is not running ? How can I read the PowerPoint version installed on a PC when it's not running ?
Also, is the folder location of "Microsoft PowerPoint 15.0 Object Library" and "Microsoft PowerPoint 16.0 Object Library" and other versions change if you run the PC on different Windows Versions ? Like Win7 32-bit is different than Win10 32-bit ? and different than Win10 64-but ?
"Bonus" Question: I couldn't find anywhere online a chart (or a list) that stores all the data for folder locations of the "MSPPT.OLB" file, for different operating systems, and different Office versions.
My Current Code
Option Explicit
Sub RemoveMissingReferences_AddReference()
' display Windows Version installed on this PC
' Win7. (=6.1, 64bit)
' Win8 (=6.2, 64bit)
' Win8.1 (=6.3*)
' Win10 (=10.0*)
'
MsgBox "Windows Version is: " & getVersion
MsgBox "Excel Version is: " & Application.Version
Dim theRef As Variant, i As Long
Dim ProjRef() As String
ReDim ProjRef(1 To ThisWorkbook.VBProject.References.count)
'Remove any missing references
For i = ThisWorkbook.VBProject.References.count To 1 Step -1
Set theRef = ThisWorkbook.VBProject.References.Item(i)
ProjRef(i) = theRef.FullPath ' read path to string array , will use it later
' if reference is "Missing" >> remove it to avoid error message
If theRef.isbroken = True Then
ThisWorkbook.VBProject.References.Remove theRef
End If
Next i
' add a Reference to PowerPoint , according to version running on the PC
Dim NewRef_FullPath As String
NewRef_FullPath = "C:\Program Files (x86)\Microsoft Office\Office14\MSPPT.OLB" ' Add PowerPoint 2010 Windows 7-32Bit
' loop through all existing references and check if new requested reference already checked
For i = 1 To UBound(ProjRef)
If InStr(1, ProjRef(i), NewRef_FullPath) > 0 Then ' reference already installed on PC >> pevious code runs
MsgBox "New Ref already installed"
Exit Sub
End If
Next i
On Error GoTo CanNotAddPowerPoint
Application.VBE.ActiveVBProject.References.AddFromFile NewRef_FullPath 'try to add a reference to PowerPoint
MsgBox "New Ref successfully installed"
Exit Sub
CanNotAddPowerPoint:
MsgBox "Can not reference PowerPoint"
End Sub
Debug.Print Environ$("Path")
. I have no clue if this holds true for other Office versions or systems though. – Comintern