VBA Does Not Compile Suddenly? Listing Reference Settings to Find BROKEN References

VBA・Officeカテゴリを表すパンダのイラスト VBA / Office

About This Article
This article is generated using an automated workflow powered by generative AI. It re-verifies Microsoft Learn's VBA reference settings and Office security documentation along with existing Daily-Code-Samples, organizing a procedure to safely list broken references.

Verification Status: 📘 Official Information Confirmed – Excel Physical Device Not Verified

When VBA suddenly stops compiling on another PC, it is worth suspecting the MISSING in the reference settings.ThisWorkbook.VBProject.References By enumerating the IsBroken and checking the

you can isolate broken references from your code.

Get Started First

Option Explicit

Public Sub CheckReferences()
    Dim ref As Object
    Dim brokenCount As Long

    On Error GoTo AccessDenied

    Debug.Print "[START] 参照設定を確認します"

    For Each ref In ThisWorkbook.VBProject.References
        If ref.IsBroken Then
            brokenCount = brokenCount + 1
            Debug.Print "[BROKEN]", "壊れた参照"
        Else
            Debug.Print "[OK]", ref.Name, ref.Major & "." & ref.Minor
        End If
    Next ref

    Debug.Print "[RESULT] Broken=" & brokenCount
    Exit Sub

AccessDenied:
    Debug.Print "[FAILED]", Err.Number, Err.Description
End Sub

This operation uses access to the VBA project object model. On corporate PCs, prioritize organizational policies and do not change settings arbitrarily.

Microsoft Support – Change macro security settings in Excel

Check Here[OK]Display the [BROKEN] and Broken=0 separately in the Immediate Window. If

flowchart TD
    A[Referencesを列挙] --> B{IsBroken?}
    B -- No --> C[Name / Versionを表示]
    B -- Yes --> D[BROKENとして記録]
    C --> E[次の参照]
    D --> E

then no broken references are detected. If there is one or more, cross-reference them with the references settings screen.

Do Not Recklessly Read FullPath on Broken ReferencesIsBroken=TrueWith broken references, property retrieval itself may fail. In the existing complete sample, FullPath do not read the

for references, and attempt GUID retrieval safely in a separate function.

Microsoft Learn – Reference.FullPath

Try Changing One Placeref.FullPathAdditionally display the

If Not ref.IsBroken Then
    Debug.Print ref.Name, ref.FullPath
End If

only for normal references.IsBrokenFirst, by adding one display item while keeping the

determination, you can observe broken references without increasing risky property accesses.

Why Reference Breaks Occur

Typically, these include library differences when moving to another PC, Office/ActiveX component differences, and missing reference file destinations. When a reference breaks, compile errors may occur near standard functions that appear unrelated, making listing useful as an initial triage step.

When Using for Work

  • It is safer not to proceed all the way to automatically "repairing" reference settings.

  • Only read and list first

  • Do not automatically delete even if MISSING is detected

  • Do not arbitrarily select one from multiple candidates

  • Record GUIDs and versions to check the cause

Do not loosen Office trust settings without permission

Separating auditing and repair can reduce accidents involving replacing with incorrect references.

GitHub Sample

Daily-Code-Samples – VBA reference audit

Microsoft Support – Change macro security settings in Excel

ConclusionReferencesVBA reference troubleshooting becomes easier to isolate by first reading and visualizing IsBroken and

Document information

Article title
VBA Does Not Compile Suddenly? Listing Reference Settings to Find BROKEN References
Published
Updated
Source
https://papanda925.com/?p=17057&lang=en

License: Text and original figures for which this site holds the relevant rights are available under CC BY 4.0 , unless otherwise noted. This article may include content created or edited with generative AI. If code has a separate license notice or a linked GitHub repository license, that license takes precedence for the code. Quotations, third-party materials, images, and trademarks are excluded from this license. Usage policy

Copied title and URL