Solved

How to disable VBA Error Messages due to broken or missing preferences

Posted on 2008-10-12
3
1,485 Views
Last Modified: 2013-11-25
When an Excel sheet with Macros is passed from one PC to another, it may not work due to broken or missing preferences.
Ideally I would like to check for broken links, remove them, if possible reconnect them, and possibly dump offending code.
Unfortunately I cannot do any of that, because as soon as I trigger any macro it crashed on the unrelated offending sub-routine.

Any suggestions?

Example: Removing Broken References.... but I first have to disable the error messages...
 
Dim theRef As Variant, i As Long
On Error Resume Next
For i = 1 To Application.References.Count 'Remove any missing references
Set theRef = Application.References.Item(i)
If theRef.IsBroken = True Then
Application.References.Remove (theRef)
End If
Next i

Open in new window

0
Comment
Question by:Clemens_Saur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 500 total points
ID: 22698111
You could try this approach from Dennis Wallentin. Pls note that you need to add a reference to Microsoft Visual Basic for Applications Extensibility 5.3. I have attached the notes below posted by Dennis when he provide this code in another forum

Regards

Dave

#1 A reference ISMISSING is added to the workbook VB-project references.
(Should per se not be a problem unless You call it by code or try to install it then
an error-message will be showed.

#2 The below procedure must be executed from a different workbook and the target workbook must be open.

If running Excel 2002 and above You must allow access to VB-projects via Tools - Macros... - Security.

If the add-ins VB-project is closed then You are out of luck...


VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Sub Del_Broken_Ref()
     'Add a reference to the Microsoft Visual Basic for Applications Extensibility 5.3
    Dim VBReferens As VBIDE.Reference
    Dim VBProjekt As VBIDE.VBProject
    Dim stBok As String
     
    stBok = Workbooks("Test.xls").Name
     
    Set VBProjekt = Workbooks(stBok).VBProject
     
    For Each VBReferens In VBProjekt.References
        If VBReferens.IsBroken Then VBProjekt.References.Remove VBReferens
    Next VBReferens
     
End Sub

Open in new window

0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 22698262
Clemens_Saur said:
>>Any suggestions?

Yes: wherever possible, use late binding instead of early binding.  Late binding tends to be highly tolerant of
changes in versions, whereas with early binding, sometimes you are OK, and sometimes not.
0
 

Author Comment

by:Clemens_Saur
ID: 22805934
The solution was good for removing broken reference links. The original code was not effective. The new code is perfect.
The trick to avoiding 'early crashes' due to missing reference links however is not to pass any variables which are reference dependent  between subs or functions.
I had passed a variable dimed as CodeModule. CodeModule requires the 5.3 extensions. I changed the variable from  Codemodule to String and later on converted it inside the sub or function back to CodeModule and early crashes were eliminated : )
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question