D
Derek P.
Skip to NUT & BOLTS OF IT if you don’t want the history.
I've searched and searched but cant' find someone that has found a solution
that I'm looking for, and everything I’ve tried “should†work but is failing.
Namely, I want to create a dependency checker that robustly checks all
dependencies used for my companies tool(s) written in excel, and remove
broken references, and re-add them based on the Office version.
NUT & BOLTS OF IT (I’ve included the problem function only, other functions
should be self explanatory what they do)
Macro Security > Trusted Publishers has Trust access to VB project checked.
When the workbook opens, the following code is executed:
'*********************************************************
'Function checks all currently enabled application dependencies and attempts
to
'resolve broken dependencies.
'
'Returns:
' True - No broken references encountered.
' False -
' Err.Number = 0 - Broken references encountered, but all were restored
' Err.Number = 1001 - Un-Handled exception occurred
' Err.Number = 1002 - Broken references encountered, and one or more
were ' not restored
Public Function bCheckDependencies() As Boolean
On Error GoTo ErrorHandler
Dim breturn As Boolean
Dim cbroken_references As New Collection
Dim reference As Object
'Loop through all of the application defined references to see if any are
broken
'or 'missing
For Each reference In ThisWorkbook.VBProject.References
'********************************
'I believe office is crashing at this point
If reference.isbroken = True Then
'********************************
'Add the GUID, Major, and Minor information for the broken reference
'into an array and add that to the broken ref collection.
cbroken_references.Add (Array(reference.GUID, _
reference.major, _
reference.minor))
'Remove the current broken reference
'********************************
'Or i get the "Object Library not registered" error at this point
ThisWorkbook.VBProject.References.Remove reference
'********************************
End If
Next reference
'Check to see if any of the application references were broken
If cbroken_references.Count <> 0 Then
Call RestoreBrokenDependencies(cbroken_references)
'Worksheet must be opened with all references valid, or other problems
'Spawn, return false to indicate references were missing. If Err.Number
'is 0, all references were restored correctly.
breturn = False
Else
breturn = True
End If
bCheckDependencies = breturn
Exit Function
ErrorHandler:
Select Case Err.Number
Case Else
'Pop message to user about function failure and exit.
Call iPopMSG(Array("UN-HANDLED EXCEPTION", _
Err))
Err.Clear
With Err
.Number = 1001
.Description = "Un-Handled exception occured"
.Source = "Module: " & sMODULENAME & _
vbLf & "Sub/Function: bCheckDependencies()"
End With
End Select
bCheckDependencies = False
End Function
This code functions correctly if saved in Office Excel 2003, and one of the
references are removed from the system, then re-opened in 2003. However if
the worksheet is saved in 2007 using the 2003 format, and opened on a 2003
machine where the ..\Microsoft Office\OFFICE12 folder is missing, Office will
either crash. (the reference missign is the REFEDIT.DLL for my project) or i
get an error number -2147319779: Object library not registered, either way
the result is that i can not remove the broken reference programatically,
and i believe it should be possible.
Any help would be appreciated as I've spent more than a few hours trying all
kinds of things and nothing resolves the problem.
Please let me know if additional information is needed.
Thank you,
I've searched and searched but cant' find someone that has found a solution
that I'm looking for, and everything I’ve tried “should†work but is failing.
Namely, I want to create a dependency checker that robustly checks all
dependencies used for my companies tool(s) written in excel, and remove
broken references, and re-add them based on the Office version.
NUT & BOLTS OF IT (I’ve included the problem function only, other functions
should be self explanatory what they do)
Macro Security > Trusted Publishers has Trust access to VB project checked.
When the workbook opens, the following code is executed:
'*********************************************************
'Function checks all currently enabled application dependencies and attempts
to
'resolve broken dependencies.
'
'Returns:
' True - No broken references encountered.
' False -
' Err.Number = 0 - Broken references encountered, but all were restored
' Err.Number = 1001 - Un-Handled exception occurred
' Err.Number = 1002 - Broken references encountered, and one or more
were ' not restored
Public Function bCheckDependencies() As Boolean
On Error GoTo ErrorHandler
Dim breturn As Boolean
Dim cbroken_references As New Collection
Dim reference As Object
'Loop through all of the application defined references to see if any are
broken
'or 'missing
For Each reference In ThisWorkbook.VBProject.References
'********************************
'I believe office is crashing at this point
If reference.isbroken = True Then
'********************************
'Add the GUID, Major, and Minor information for the broken reference
'into an array and add that to the broken ref collection.
cbroken_references.Add (Array(reference.GUID, _
reference.major, _
reference.minor))
'Remove the current broken reference
'********************************
'Or i get the "Object Library not registered" error at this point
ThisWorkbook.VBProject.References.Remove reference
'********************************
End If
Next reference
'Check to see if any of the application references were broken
If cbroken_references.Count <> 0 Then
Call RestoreBrokenDependencies(cbroken_references)
'Worksheet must be opened with all references valid, or other problems
'Spawn, return false to indicate references were missing. If Err.Number
'is 0, all references were restored correctly.
breturn = False
Else
breturn = True
End If
bCheckDependencies = breturn
Exit Function
ErrorHandler:
Select Case Err.Number
Case Else
'Pop message to user about function failure and exit.
Call iPopMSG(Array("UN-HANDLED EXCEPTION", _
Err))
Err.Clear
With Err
.Number = 1001
.Description = "Un-Handled exception occured"
.Source = "Module: " & sMODULENAME & _
vbLf & "Sub/Function: bCheckDependencies()"
End With
End Select
bCheckDependencies = False
End Function
This code functions correctly if saved in Office Excel 2003, and one of the
references are removed from the system, then re-opened in 2003. However if
the worksheet is saved in 2007 using the 2003 format, and opened on a 2003
machine where the ..\Microsoft Office\OFFICE12 folder is missing, Office will
either crash. (the reference missign is the REFEDIT.DLL for my project) or i
get an error number -2147319779: Object library not registered, either way
the result is that i can not remove the broken reference programatically,
and i believe it should be possible.
Any help would be appreciated as I've spent more than a few hours trying all
kinds of things and nothing resolves the problem.
Please let me know if additional information is needed.
Thank you,