How to Remove Historian from active project via VBA

How to Remove Historian from active project via VBA

I have a code to remove some archive matching the rule from array
The code like below seems to work but not all the time. I'm getting error :
run-time error '438'
Object doesn't support this property or method
but when I remove archive causing exception manually and run script again some archive will be removed and again I have error.
Any ideas ?
Br. L.
VBA Code:

Private Sub CommandButton1_Click()
Dim zProject As Project
Dim zArchivesED As ArchivesED
Dim Rule()
Dim test() As String
Dim i As Integer
Dim idx As Integer
Dim jdx As Integer
Set zArchivesED = thisProject.ArchivesED
Rule = Array("*Archive1*", "*archive2*")
ReDim test(0)
jdx = 0
For i = 0 To zArchivesED.Count - 1 Step 1
For idx = 0 To UBound(Rule())
If zArchivesED.Item(i).DynProperties("LongName") Like Rule(idx) Then
ReDim Preserve test(jdx)
test(jdx) = zArchivesED.Item(i).DynProperties("ShortName")
jdx = jdx + 1
End If
Next idx
Next i

For i = 0 To UBound(test())
Debug.Print i & zArchivesED.Item(i).DynProperties("ShortName") & "-" & zArchivesED.Item(i).DynProperties("LongName")
zArchivesED.DelAirchive CStr(test(i))
Next i

Debug.Print "end"
End Sub


This is a migrated post! Originally posted on 17.07.2013 by user rrkobra. Please be aware that information can be outdated.