In/Uitschakel van References.AddFromGuid

  • Onderwerp starter Onderwerp starter dprod
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

dprod

Gebruiker
Lid geworden
2 jun 2010
Berichten
80
Beste mede forumleden,

ik heb de volgende code bij het openenen van mijn workbook:
Code:
Private Sub Workbook_Open()

    Dim ErrorMessage As String, LogFileName As String
    Dim ErrorCount As Integer, FileNum As Integer

ErrorCount = 1
On Error GoTo ErrMsg:
ThisWorkbook.VBProject.References.AddFromGuid "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 2, 0
ErrorCount = 2
On Error GoTo ErrMsg:
ThisWorkbook.VBProject.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 3

If ThisWorkbook.VBProject.VBComponents("ClassModule") Is Nothing Then
    ErrorCount = 3
    On Error GoTo ErrMsg:
        Application.VBE.ActiveVBProject.VBComponents.Import _
        (ThisWorkbook.Path & "\classmodule.bas")
End If
If ThisWorkbook.VBProject.VBComponents("ClassModule") Is Nothing Then
    ErrorCount = 4
    On Error GoTo ErrMsg:
        Application.VBE.ActiveVBProject.VBComponents.Import _
        ("G:\GBDH\ALGEMEEN\database\classmodule.bas")
End If
ErrorCount = 0

ErrMsg:
If ErrorCount = 1 Then ErrorMessage = "Reference: {0D452EE1-E08F-101A-852E-02608C4D0BB4} is niet geladen."
If ErrorCount = 2 Then ErrorMessage = "Reference: {0002E157-0000-0000-C000-000000000046} is niet geladen."
If ErrorCount = 3 Then ErrorMessage = "VBComponent: " & ThisWorkbook.Path & "\classmodule.bas is niet geladen."
If ErrorCount = 4 Then ErrorMessage = "VBComponent: G:\GBDH\ALGEMEEN\database\classmodule.bas is niet geladen."

If ErrorCount >= 1 Then
LogFileName = ThisWorkbook.Path & "\LogFile.txt"
FileNum = FreeFile
Open LogFileName For Append As #FileNum
Print #FileNum, "[" & Format(Date, "dd-mm-yyyy") & " " & Format(Time, "hh:mm") & "] " & ThisWorkbook.Name & " geopend door " & Environ("Username") & " ERROR: " & ErrorMessage
Close #FileNum
End If
ErrorCount = 0
Resume Next

    Call ExecuteFileSystem

End Sub

in mijn log wordt nu altijd weergegeven:
[08-02-2011 09:28] Tijdkaart 2011nieuwtest.xls geopend door **** ERROR: Reference: {0D452EE1-E08F-101A-852E-02608C4D0BB4} is niet geladen.
[08-02-2011 09:28] Tijdkaart 2011nieuwtest.xls geopend door **** ERROR: Reference: {0002E157-0000-0000-C000-000000000046} is niet geladen.


wat inhoud dat de references blijkbaar niet goed geladen zijn, TOCH staan ze aangevinkt in VBA. Misschien staan ze al aangevinkt? maar naar mijn weten sluit ik ze juist met de volgende code ook gewoon netjes af...

bij de workbook close roep ik de volgende sub op:
Code:
Public Sub CloseDatabase()

    Dim wb As Workbook
    Dim Reference As Object

For Each Reference In ThisWorkbook.VBProject.References
    If Reference.Description = "Microsoft Visual Basic for Applications Extensibility 5.3" Then
        ThisWorkbook.VBProject.References.Remove Reference
    End If
Next
For Each Reference In ThisWorkbook.VBProject.References
    If Reference.Description = "Microsoft Forms 2.0 Object Library" Then
        ThisWorkbook.VBProject.References.Remove Reference
    End If
Next

    On Error Resume Next ' = GEEN LOG MELDING VOOR NODIG
    Set wb = Workbooks(strDatabaseFile)

If Not (wb Is Nothing) Then
wb.Close SaveChanges:=False
End If

    EnableCut

LogInformation "[" & Format(Date, "dd-mm-yyyy") & " " & Format(Time, "hh:mm") & "] " & ThisWorkbook.Name & " afgesloten door " & Environ("Username")
Application.ScreenUpdating = True

End Sub

Gebruik ik de methode op de verkeerde manier? mis ik een stukje code? of zet VBA automatisch al Forms 2.0 aan als je excel opent waardoor de error veroorzaakt wordt?
het gekke is dat als je een nieuw Excel bestand opent en naar de references kijkt ze wel gewoon uit staan. Ik ben een BEETJE de draad kwijt.
Alvast bedankt...

Gr,
dprod
 
Ik heb het opgelost door eerst te kijken of de het Object al bestaat ja of nee.
Zie Code (in het kort)...

Code:
Public Sub OpenDatabase()

    Dim VBd As Boolean
    Dim Reference As Object

For Each Reference In ThisWorkbook.VBProject.References
    If Reference.Description = "Microsoft Visual Basic for Applications Extensibility 5.3" Then
        VBd = True
    Else
        VBd = False
    End If
Next

    If VBd = False Then
        ErrorCount = 4
        On Error GoTo ErrMsg
        ThisWorkbook.VBProject.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 3
    End If

End Sub

Iedergeval dank!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan