You will need to search for the file in the vault using EdmLib.IEdmSearch5 then loop through the result(s) using EdmLib.IEdmSearchResult5 to get the path. Although newer API documentation no longer includes VBA, you can look at the examples for VB.Net which will be close.
I would export a list of files from the vault using the Search tool and do a LOOKUP to get the path. Michael's solution will work of course, but it may be more overhead than is required. Once you have the path you can get the file using oVault.GetFileFromPath.
I am in need of something like this as well. I have a excel VBA macro working, searching for parts numbers and getting results. Now what I need, and can't find a way to do, is to get the variable & values for a file. I would like to get all variables and then I can loop through for what I need in VBA. I looked at the results but did not find any variable info. I tried Search.AddVariable but I never got it to work and feel it is not really the correct way to go about this. Would someone post VBA code on how they have done this?
Here is a macro that gets all variables in all configurations and writes them into a sheet. You can use it for starting with variables and modify it to your needs.
' Use the 'PDMWorks Enterprise xxxx Type Library'
' e.g. C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS PDM\EdmInterface.dll
' Sheet name in which the variables and values will be written
Const sheetName = "<sheet name>"
' Vault name
Const epdmVault = "<vault name>"
' File name from which the variables will be read
Const fName = "<file name with path>"
' Variables in loops
Dim currentRow As Long
Dim currentColumn As Long
currentColumn = 1
Dim i As Long
' Log into the vault
Dim vault5 As EdmVault5
Set vault5 = New EdmVault5
If Not (vault5.IsLoggedIn) Then
vault5.LoginAuto epdmVault, 0
' Objects for the specified file and folder
Dim file5 As IEdmFile5
Dim folder5 As IEdmFolder5
' Gets the object for the file
Set file5 = vault5.GetFileFromPath(fName, folder5)
' Objects for the variables
Dim var7 As IEdmEnumeratorVariable7
Dim ppoRetVars() As Variant
Dim ppoRetConfs() As String
Dim poRetDat As EdmGetVarData
Dim var6 As IEdmVariableValue6
' Gets all variables in all configurations from the database
Set var7 = file5.GetEnumeratorVariable
var7.GetVersionVars 0, folder5.ID, ppoRetVars, ppoRetConfs, poRetDat
' Objects for the configurations
Dim configs As EdmStrLst5
Dim pos5 As IEdmPos5
Dim config As String
' Gets the configurations for the current file
Set configs = file5.GetConfigurations()
Set pos5 = configs.GetHeadPosition()
' Loop over all configurations
While (Not pos5.IsNull)
currentRow = 1
' Gets the current configuration name
config = configs.GetNext(pos5)
Sheets(sheetName).Cells(currentRow, currentColumn).Value = config
'Gets all variables and values for the current configuration and writes them into the sheet
For i = LBound(ppoRetVars) To UBound(ppoRetVars)
currentRow = currentRow + 1
Set var6 = ppoRetVars(i)
Sheets(sheetName).Cells(currentRow, currentColumn).Value = var6.VariableName
Sheets(sheetName).Cells(currentRow, currentColumn + 1).Value = var6.GetValue(config)
currentColumn = currentColumn + 2
Thanks! That was just what I needed!