AnsweredAssumed Answered

VBA Macro to search through PDM and Pack and Go

Question asked by Mark Trupiano on Apr 26, 2019
Latest reply on Apr 27, 2019 by Ulf Stockburger

I'm attempting to write a macro that finds a specified file in a PDM server, and then 'Pack-and-Go's' it to a specified local location. I'm using a recursive function and the FileSystemObject to search through a folder and all subfolders on our PDM, and check each file name in every subfolder against the specified search file name. For some reason, though, the macro isn't checking every file. It will only check through a seemingly random set of files in the folder, ignoring others, and then it will move on to the next folder/subfolder. I'm really not sure what the problem is, I've tried debugging and manually printing everything the macro is doing to the Immediate window, but I can't pinpoint why it's just ignoring certain files. I've pasted a simplified version of the recursive file-search code below, I left out the bits of the code that does the Pack-and-Go operation. Any help is appreciated!


Sub main()

    Recurse ("C:\Vault\Library")

End Sub


Function Recurse(sPath As String) As String

    Dim FSO As New FileSystemObject

    Dim myFolder As Folder

    Dim mySubFolder As Folder


    Set myFolder = FSO.GetFolder(sPath)

    For Each mySubFolder In myFolder.SubFolders

        Call TestSub(mySubFolder.Path)

        Recurse = Recurse(mySubFolder.Path)



End Function


Sub TestSub(ByVal s As String)

    Dim FSO As New FileSystemObject

    Dim myFolder As Folder

    Dim myFile As File


    Set myFolder = FSO.GetFolder(s)

    For Each myFile In myFolder.Files

        If myFile.Name = "EXAMPLE_FILE_NAME.SLDPRT" Then

            Debug.Print "FILE FOUND"

            'Here is where I'd run a subroutine that performs a Pack-and-Go on the found file

        End If



End Sub