VBA Assign an EDMVAULT5 instance with the "Late Binding" technique

Hello

in the VBA editor, when you check the boxes in the reference manager, you do "early binding". This means that at compile time, VBA scans the references and knows all types of objects. This makes it possible to write:

Dim eVault as EdmVault5 : Set eVault = New EdmVault5

 

The downside to this method is that it is not portable. It is often recommended in VBA to do "late binding". It is recommended to write:

Dim eVault as Object: Set eVault = CreateObject("ConisioLib.EdmVault")

 

Where I have problems is that I get an EdmVault21 object, "pure", which does not inherit from the other versions of EdmVault, especially EdmVault 5 and its GetFileFromPath() method. And I don't know how to "cast" in vba.

Hence my question, how do I create an edmVault5 object in late binding?

I would like to point out that if I do late binding, it is because early binding does not work in my case. I'm not writing a macro but code for an ePDM task. This very special task does things that have a remote connection with CAD, but I need to insert the resulting file into the vault.

Thank you

I am in the same situation!! A solution found since then? 

Hello
For my part, I ported my code to an executable in vb.net. The task's vba macro prepares the command line and calls this executable. No more problems with declaration and reference.

1 Like

Thank you for your answer! I finally succeeded via the VBA :) 

@yves-marie.freyssinet 

OK... But if instead of just taunting the community, you could share your solution with them to help them as they help you, it would be generous of you.

1 Like

I'm not taunting anyone! I hadn't finished my macro yet.... But everything is good and functional:)  So I am happy to share what I have found and I hope that the time I have spent searching will be beneficial to others!  

Here is the macro I managed to make by doing late blinding as binoyte explains, it is used to extract a file via the PDM script: 

Sub main()

Dim Vault As Object
Set Vault = CreateObject("ConisioLib.EdmVault")

Vault.LoginAuto "NOM_COFFRE_PDM", 0

modelPath = "<Filepath>"
    
    If Vault.IsLoggedIn Then
    
        Dim folder As Object
        Dim folderPath As String
        Dim FolderPath1 As String
        folderPath = modelPath
        j = InStrRev(folderPath, "\")
        FolderPath1 = Left(folderPath, j)

    Set folder = Vault.GetFolderFromPath(FolderPath1)
    
      i = Len(modelPath)
      j = InStrRev(modelPath, "\")
      FileName = Right(modelPath, i - j)

  Dim file As Object
  Dim oNull As Object
  Set file = folder.GetFile(FileName)
    
    If file Is Nothing Then

        MsgBox "File not found."
    End If


  file.LockFile folder.ID, 0
  CheckOutFile = "Successful"
        
        
    Else
        Err.Raise vbError, "User is not logged in to the vault"
    End If


End Sub

**Don't forget to replace the 'NOM_COFFRE_PDM' with your pdm vault name:) 

1 Like

Sorry for the mistake but this kind of answer is so recurrent on the net...

Bravo for the macro and Thanks for sharing;)

1 Like

Thank you. So  what makes it work?

You are bothered with the treatment of your paths. You should use the Scripting.FileSystemObject library

' Chargement de l'objet Système de Fichiers 
Dim oFS As Object
Set oFS = CreateObject("Scripting.FileSystemObject")

sInputFile = "<Filepath>"

Look in the object explorer for other methods in this library and its parent, Scripting, in general. It's pretty practical!

1 Like

From what I read and could find as info, once I created the following object: 

Dim Vault As Object
Set Vault = CreateObject("ConisioLib.EdmVault")

just declare for example  "Folder As Object" instead of "Folder As IEdmFolder5" and it works, the same for other statements of the same type:) 

Thank you very much for the info about the processing of file paths, I'll take a closer look at it!! I'm not an expert in VBA macro yet ahah and I'm glad I have some advice:) 

Looking forward to sharing more tips! 

Ah, when I open my eyes, I understand better why it works for you and not for me!

You use the method:

Vault.GetFolderFromPath()

 

which has never been a problem for me by the way, but in my case, I use the method:

Vault.GetFileFromPath()

 

And there it doesn't work. So my problem remains.

Here is my minimal example:

Sub ajoutfich()
    Dim eVault, eFile, eFolder As Object
    Dim iStatus As Integer
    Dim sFichier, sDestination, sSource As String
    
    Dim oFS As Object
    Set oFS = CreateObject("Scripting.FileSystemObject")
    
    sDestination = "D:\ePDM\…\dossier\"
    sSource = "E:\FICHIER.EXT"
    sFichier = oFS.buildpath(sDestination, oFS.GetFileName(sSource))

    Set eVault = CreateObject("ConisioLib.EdmVault")
    If Not eVault.IsLoggedIn Then
        eVault.LoginAuto "MON_COFFRE_PDM", 0
    End If

    Set eFolder = eVault.GetFolderFromPath(sDestination)
    
    Set eFile = eVault.GetFileFromPath(sFichier)
    If Not eFile Is Nothing Then
        'à complèter
    End If
    
    iStatus = eFolder.AddFile(0, sSource)
End Sub

 

I'm getting runtime error 13: type mismatch for row:

Set eFile = eVault.GetFileFromPath(sFichier)

 

However, the casting seems to be done automatically. When we look at the VBA spy window (see attached screenshot),  we can see IEdmVault5 objects. Also, the eVault.LoginAuto() method  depends on the IEdmVault5.

So why is it stuck on eVault.GetFileFromPath()?


1659427953.screenshot.png

Hello

One argument is missing:

Set eFile = eVault.GetFileFromPath(sFichier, eFolder)

 

Hello

Isn't it supposed to be optional?

 

EDIT: out of conscience, I tested as you indicated, same mistake!

It doesn't seem to me, except to put 0

Hello

No problem with me with the eFolder argument, otherwise same error by having just sFile

What if you try using the following statement instead of the "Set eFile = eVault.GetFileFromPath(sFile)"?

Dim efolder As Object
Dim sFichier As Object

Set eFile = efolder.GetFile(sFichier)

Does it work or not?

The doc page: GetFileFromPath Method (IEdmVault5)

It's optional, and I had also tried with 0.

Thank you for your answer but... damn! I'm wondering if I should take a look at the dll recording with regsrv32.

I think about this because I tried to create an EdmFile object directly:

Set eFile = CreateObject("ConisioLib.EdmFile")

and I get a run-time error 429: an activeX component cannot create an object.

1 Like

I admit that this may be a little beyond my skills ahaha but I'm still available if you manage to unblock or move forward:)