Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
Wildcard (*) not working. When searching a folder for a document with variable file type, the "*" function does not seem to be working

I'm having issues with the wildcard *. I want to search for a document in a folder and return its location. The issue is that the document can be either .xlsx or .pdf; therefore, I wanted to add "*" to the name so that it would find either.

I have this:

Sub Test2()
    Dim FSO As New FileSystemObject
    Dim myFolder As Scripting.Folder
    Dim mySubFolder As Scripting.Folder
    Dim myFile As File

    Set myFolder = FSO.GetFolder("Folder Path")
    Set Team3 = ThisWorkbook.Worksheets("Team 3 & 3a")
    Rng = Team3.Range("B4:B9")
    
    For Each batch In Rng    
        Filename = batch & "*"

        For Each mySubFolder In myFolder.SubFolders        
            For Each myFile In mySubFolder.Files            
                If myFile.Name = Filename Then                
                    MsgBox myFile.Path
                    Exit For                    
                End If                
            Next            
        Next               
    Next
End Sub

The issue I'm having is that, the wildcard * doesn't seem to be working and it seems to be interpreting it as text. If I replace the "*" with ".pdf" it does indeed find the files, but I needed it to search for any type of file.

I have removed the folder path from the above, but it is indeed searching in the correct folder. The code itself works, its just the "*" that doesn't seem to work.

Any help would be greatly appreciated.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Thank you, FunThomas for helping with this. Not sure how this site works, but the following was the answer given by him.

Sub Test2()    
    Dim FSO As New FileSystemObject
    Dim myFolder As Scripting.Folder
    Dim mySubFolder As Scripting.Folder
    Dim myFile As File

    Set myFolder = FSO.GetFolder("Folder Path")
    Set Team3 = ThisWorkbook.Worksheets("Team 3 & 3a")
    Rng = Team3.Range("B4:B9")

    For Each batch In Rng        
        Filename = batch & "*"
    
        For Each mySubFolder In myFolder.SubFolders            
            For Each myFile In mySubFolder.Files                
                If myFile.Name Like Filename Then                    
                    MsgBox myFile.Path
                    Exit For                        
                End If                    
            Next                
        Next                    
    Next        
End Sub
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda