Get document ID from word application

Hi,

I would like to get properties of a word document (docm) that is opened from M-Files in vba. Essentially I just need the document ID. I got this information before by using the M-Files ribbon and adding it to a cell where I read it from, but I am sure there must be a easier way to get it.

Please let me know if you have some ideas.

  • Ok, I found a way to get the ID, it is to use the FindObjectVersionAndProperties method from the MFilesClientApplication object. It uses the ThisDocument.FullName to get the current word / excel document's full path on M-files (ex. M:\VaultName\...\filename.docm) and returns the ObjectVersionAndProperties where you can get any info of that object further.

    Here is the piece of code, you just need to change the name of the vault:

    Function BindToVault() As MFilesAPI.vault
    
        ' Read the name of the vault to bind on client side.
        Dim szVaultName As String: szVaultName = "VaultName"
        
        ' Instantiate an object that represents the M-Files application.
        ' This is the base object that must be used to perform any other operations.
        ' Note: via this object we communicate with the M-Files Client software.
        Dim oMFAPIApp As MFilesAPI.MFilesClientApplication
        Set oMFAPIApp = CreateObject("MFilesAPI.MFilesClientApplication")
        
        ' Bind to given vault.
        Dim oVault As MFilesAPI.vault
        Set oVault = oMFAPIApp.BindToVault(szVaultName, 0, True, True)
        
        ' Return value.
        Set BindToVault = oVault
        
        
        ' Locate the object by path from M-Files.
        Dim oObjVerAndProp As MFilesAPI.ObjectVersionAndProperties
        Set oObjVerAndProp = oMFAPIApp.FindObjectVersionAndProperties(ThisDocument.FullName)
        
        ' Get the object version ID of the current document
        Dim objectVersionID As Long
        objectVersionID = oObjVerAndProp.ObjVer.ID
    
        MsgBox "The ObjectVersionID of the current document is: " & objectVersionID
        
        ' Release resources.
        Set oMFAPIApp = Nothing
        Set oVault = Nothing
    
    End Function