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.

    Disclaimer

    This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.

    The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.

    Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.

    Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.

    COPA-DATA reserves the right to change this document from time to time at own discretion.


    Ing. Punzenberger COPA-DATA GmbH
    Karolingerstraße 7b · 5020 Salzburg · Austria
    www.copadata.com