Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

vba subfolder search

2 REPLIES 2
Reply
Message 1 of 3
jdchakes
910 Views, 2 Replies

vba subfolder search

Hi

I am trying to search through a folder and all subsequent subfolders for a file matching a certain name.

I am having trouble getting this to work.

Here is the section of my code doing the searching. I keep getting a type mismatch on the 12th line

'Recursvly check all folders and subfolders for file matching BKT UID
'NOTE!! tools/Reference/'microsoft scripting runtime' must be ticked!!
Private Sub Recurse(oAsmPath As String, bktUID As String)

Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder
Dim myFile As File

Set myFolder = FSO.GetFolder(oAsmPath)

For Each mySubFolder In myFolder.SubFolders
For Each myFile In mySubFolder.Files
If InStr(myFile.Name, bktUID) <> 0 Then
Debug.Print myFile.Name & " in " & myFile.Path
Exit For
End If
Next
oAsmPath = mySubFolder.Path
Call Recurse(oAsmPath, bktUID)
Next

End Sub

 

I am not very experienced at programming at all so any help would be appreciated cheers!

2 REPLIES 2
Message 2 of 3
rossano_praderi
in reply to: jdchakes

Hi Jd, this is my solution.

 

Private Sub Recurse(oAsmPath As String, bktUID As String)

 Dim FSO As New FileSystemObject
 Dim myFolder As Folder
 Dim mySubFolder As Folder
 Dim myFile 'As File

 Set myFolder = FSO.GetFolder(oAsmPath)

 For Each mySubFolder In myFolder.SubFolders
    For Each myFile In mySubFolder.Files
       'If InStr(Ucase(myFile.Name), Ucase(bktUID)) <> 0 Then 'not case sensitive as an example
       If InStr(myFile.Name, bktUID) <> 0 Then
          Debug.Print myFile.Name & " in " & myFile.Path
          Exit For
       End If
    Next
    oAsmPath = mySubFolder.Path
    Call Recurse(oAsmPath, bktUID)
 Next

End Sub

 



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 3 of 3
rossano_praderi
in reply to: jdchakes

Hi Jd, have you found a solution?

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report