Search code examples
vbacomboboxxlsm

Add only xlsm files to combobox VBA


It's my first time asking something in this forum, i have this code that adds some files to a combobox in a User Form, but the thing is i only need to add the .xlsm files, but the code i came up with adds me every file, how can I do something like that?

Here's my code:

Dim Pathh As String
Dim fila As Integer
Set fso = CreateObject("Scripting.FileSystemObject")
Path = "Z:\Primera Inspección\" & Alertas_Mes.Controls("Label" & i).Caption
Set carpeta = fso.getfolder(Path)
If carpeta <> Pathh Then GoTo Sig
Set ficheros = carpeta.Files  
For Each ficheros In ficheros

    b = ficheros.Name
    Alertas_Mes.Controls("Combobox" & i).AddItem b
Next ficheros

Solution

  • Should be something as simple as putting in an If statement

    Dim Pathh As String
    Dim fila As Integer
    Set fso = CreateObject("Scripting.FileSystemObject")
    Path = "Z:\Primera Inspección\" & Alertas_Mes.Controls("Label" & i).Caption
    Set carpeta = fso.getfolder(Path)
    If carpeta <> Pathh Then GoTo Sig
    Set ficheros = carpeta.Files  
    For Each ficheros In ficheros
    
        b = ficheros.Name
        if(b like "*.xlsm") then
            Alertas_Mes.Controls("Combobox" & i).AddItem b
        end if
    Next ficheros