Hello, everybody.
I have the following code which works in Excel 2013 but it not working in Excel 2010. It has 2 problems:
1: It doesnt remove missing reference, as it was supposed to do;
2: After manually removing the powerpoint missing reference and adding the correct one, it enters a LOOP in the lines:
The code down here I got from different google searchs, unfortunately i dont know the author to send the credits.
Can someone help me?
I have the following code which works in Excel 2013 but it not working in Excel 2010. It has 2 problems:
1: It doesnt remove missing reference, as it was supposed to do;
2: After manually removing the powerpoint missing reference and adding the correct one, it enters a LOOP in the lines:
Code:
'Remove any missing references For y = ThisWorkbook.VBProject.References.Count To 1 Step -1
Set theRef = ThisWorkbook.VBProject.References.Item(y)
If theRef.isbroken = True Then
ThisWorkbook.VBProject.References.Remove theRef
End If
Next y
The code down here I got from different google searchs, unfortunately i dont know the author to send the credits.
Can someone help me?
Code:
'Macro purpose: To add a reference to the project using the GUID for the
'reference library
'Update the GUID you need below.
strGUID = "{91493440-5A91-11CF-8700-00AA0060263B}"
'Set to continue in case of error
On Error Resume Next
'Remove any missing references
For y = ThisWorkbook.VBProject.References.Count To 1 Step -1
Set theRef = ThisWorkbook.VBProject.References.Item(y)
If theRef.isbroken = True Then
ThisWorkbook.VBProject.References.Remove theRef
End If
Next y
'Clear any errors so that error trapping for GUID additions can be evaluated
Err.Clear
'Add the reference
ThisWorkbook.VBProject.References.AddFromGuid _
GUID:=strGUID, Major:=1, Minor:=0
'If an error was encountered, inform the user
Select Case Err.Number
Case Is = 32813
'Reference already in use. No action necessary
Case Is = vbNullString
'Reference added without issue
Case Else
'An unknown error was encountered, so alert the user
MsgBox "A problem was encountered trying to" & vbNewLine _
& "add or remove a reference in this file" & vbNewLine & "Please check the " _
& "references in your VBA project!", vbCritical + vbOKOnly, "Error!"
End Select
On Error GoTo 0