cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need Help to use API Macro

sgonthey
Super Contributor

Hello Community,

 

I write a macro to extract a list of services with their  HexaIdAbs  store in an excel file ( only one column in this file with the HexaIdAbs ) . It  doesn't work and I Don't Know why  !

Here my code :

 

    Dim oMegaCurrentEnvironment As New MegaCurrentEnv
    Set oMegaRoot = oMegaCurrentEnvironment.GetRoot
    Dim oCollection As New Collection
  
    x = 9
    Y = 4
      
'Tant qu’on trouve quelquechose dans la cellule active
While Sheet1.Cells(x, Y).Value <> ""
   oObject = oMegaRoot.GetSelection("Select [Service applicatif] where [_HexaIdAbs]= """ & Sheet1.Cells(x, Y) & """")

   nb = oObject.Count
   If nb = 0 Then
     'On ne fait  rien, Service non trouvé
     sErreur = "Service spécifié non trouvé"
   Else
    oCollection.Add (oObject)
    sErreur = "Service exporté avec succès"

   End If

 

   Sheet1.Cells(x, Y + 1).Value = sErreur
   x = x + 1
Wend


  oCollection.Extract.SaveAs "C:\temp\exportService.mgr"
 Set oMegaRoot = Nothing

 

oCollection should contain 537 elements but oCollection contains only 256 ??

And the main problem is  Extract function  > "Propriétés ou méthode non gérés par cet objet"

I don't know how to declare  a new collection of 'Objects'  ...

If I write  :

 

    Dim oCollection As New MegaCollection or New MegaObject, the Add funtion doesn't work anymore !

 

Thanks a lot for your Help !

 

 

2 Replies

Hi,

 

To create an empty collection, you could this:

 

Set emptyCollection = oMegaRoot.GetSelection("")

 

Also to find an object by its HexaIdabs :

 

Set myObject = oMegaRoot.getObjectFromId("D57DF6B951E89AA0")

If myObject.Exists Then

   'found

Else

  'not found
End If

 

Gregory

 

sgonthey
Super Contributor

Well, I found a solution that works  but  it's not very "clean"

I don't know how to create a new oCollection.  I searched a test object to initialize oCollection to bypass the creation

 

    Dim oMegaCurrentEnvironment As New MegaCurrentEnv
    Set oMegaRoot = oMegaCurrentEnvironment.GetRoot
    
  
 oCollection = oMegaRoot.GetSelection("Select [Service applicatif] where [nom court]= ""test""")
While Sheet1.Cells(x, Y).Value <> ""
   oObject = oMegaRoot.GetSelection("Select [Service applicatif] where [_HexaIdAbs]= """ & Sheet1.Cells(x, Y) & """")
 
   nb = oObject.Count
   If nb = 0 Then
     sErreur = "Service spécifié non trouvé"
   Else
    oCollection.Insert (oObject)
     sErreur = "Service exporté avec succès"
   End If
   Sheet1.Cells(x, Y + 1).Value = sErreur
   x = x + 1
Wend
  oCollection.Extract.SaveAs "C:\temp\export2.mgr"
 Set oMegaRoot = Nothing