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.
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.
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.
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:)
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:)
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.