Error in Macro

Hi,

I have this macro, whenever I have 2 documents it works fine, but if have more documents the Corel stops responding.

Can anyone help me?

Sub tentativa3()

    Dim d As Document, d1 As Document
    Dim x As Integer
    Dim n As String, n1() As String, n2 As String
  
    x = 0
    
    For Each d In Documents
        If x = 0 Then
            d.Activate
            x = 1
        End If
    Next d
    
    For Each d In Documents
    
        MsgBox (d.Name)
        If d.Name Like "*-TRIMS*" Then
            d.Close
            ActiveWindow.Refresh
        End If
        
        If d.Name Like "*-FABRIC*" Then
            aux = 0
            d.Activate
            n = d.Name
            n1 = (Split(n, "-"))
            n2 = n1(0) & "-" & n1(1)
            
            MsgBox (n2)
            MsgBox (d.Name)
            MsgBox (d.Active)
            For Each d1 In Documents
                If d1.Name Like n2 & "-TRIMS*" Then
                    d1.Activate
                    MsgBox (d1.Name)
                    MsgBox (d1.Active)
                End If
            Next d1
            
            d.Close
        ActiveWindow.Refresh
        End If
            
    Next d

End Sub

Parents
No Data
Reply Children
No Data