AnsweredAssumed Answered

Setvar doesn't work in Vba

Question asked by Rafael Veiga on Jan 25, 2019
Latest reply on Jan 25, 2019 by Rafael Veiga

Hi,

I am trying to create a macro to modify some variables of a file card. I thought it would be quite easy but I am struggling with Setvar. This is basically the code:

 

    Dim abc As String

    Dim retval As Variant

    Dim j As Boolean

    Dim File As IEdmFile5

    Dim Folder As IEdmFolder11

    Dim RootFolder As IEdmFolder11

    Dim VarMgr As IEdmVariableMgr7

    Dim VarPos As IEdmPos5

    Dim EnumVar As IEdmEnumeratorVariable10

    Dim configs As EdmStrLst5

    Dim pos5 As IEdmPos5

    Dim config As String

         

    Set File = Vault.GetFileFromPath(swApp.ActiveDoc.GetPathName, Folder)

    Set RootFolder = Vault.RootFolder

    Set EnumVar = File.GetEnumeratorVariable

    Set configs = File.GetConfigurations()

    Set VarMgr = Vault

    Set VarPos = VarMgr.GetFirstVariablePosition

     

    Do While Not VarPos.IsNull

        Dim Var As IEdmVariable5

         

        Set Var = VarMgr.GetNextVariable(VarPos)

        Set pos5 = configs.GetHeadPosition()

         

        Do While (Not pos5.IsNull)

            ' Gets the current configuration name

            config = configs.GetNext(pos5)

             

            If Var.Name = "Description" Then

                Select Case config

                Case "@"

                    EnumVar.SetVar Var.Name, config, "New Description", True

                End Select

            End If

            

            EnumVar.CloseFile (True)

        Loop

    Loop

End Sub

 

 

And this is the error that appears on Setvar's line:

 

Run-time error '-2147220991 (80040201)'

The program used an object without initializing it properly first.

 

Any idea of what it is happening?

 

Thank you.

 

Rafa

Attachments

Outcomes