有没有一种方法可以删除“丢失”的可用参考-参考VBAProject

时间:2019-06-18 16:10:56

标签: vba

我已经写了一个File_Picker代码,运行它时出现错误,因为它正在寻找缺少的.DLL文件。当打开“工具参考”时,有一个标记为“ MISSING”的链接。如何删除此参考?如果我取消选中引用,它会起作用。

我试图添加代码以删除引用,但我真的不知道自己在做什么,将不胜感激

文件密码:

Sub GettingFile()
    Dim SelectedFile As String
    Dim d As FileDialog

    Set d = Application.FileDialog(msoFileDialogFilePicker)

    With d

        .AllowMultiSelect = False
        .Title = "select file"
        .buttonname = "confirm"
        .initialfilename = "w:\monthly project status reports"

        If .Show = -1 Then
        'ok clicked
        SelectedFile = .selectedItems(1)
        MsgBox SelectedFile
        Else
        'cancel clicked
        End If

    End With



End Sub

尝试的修复代码:

*在标准模块中*

Option Explicit 

Sub References_RemoveMissing() 
     'Macro purpose:  To remove missing references from the VBE

    Dim theRef As Variant, i As Long 

    On Error Resume Next 

    For i = ThisWorkbook.VBProject.References.Count To 1 Step -1 
        Set theRef = ThisWorkbook.VBProject.References.Item(i) 
        If theRef.isbroken = True Then 
            ThisWorkbook.VBProject.References.Remove theRef 
        End If 
    Next i 

    If Err <> 0 Then 
        MsgBox "A missing reference has been encountered!" _ 
        & "You will need to remove the reference manually.", _ 
        vbCritical, "Unable To Remove Missing Reference" 
    End If 

    On Error GoTo 0 
End Sub

0 个答案:

没有答案