Application.GetOpenFilename avec filtre sur nom de fichier

Bonjour a tous,

j'utilise cette fonction pour importer mon fichier de commande

ChDir "D:\Telechargement"
Dim F As Variant
F = Application.GetOpenFilename("csv Files (order*.csv), order.csv")

Est il possible de filtrer le nom du fichier , je souhaiterai que n'apparaissent que les fichiers commençant par order*

Merci

Salut,

je retire comme quoi il faut tester avant...

Bon re,

En passant par un Filedialog cela passe

    Dim fd As FileDialog
    Dim FileName As String

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .Filters.Clear
        .Filters.Add "Fichiers Texte", "*.csv"
        .Title = "Sélectionnez le document"
        .InitialFileName = ActiveWorkbook.Path & "\order*.csv*"
    End With
    If fd.Show = True Then FileName = fd.SelectedItems(1)

    If Not fd Is Nothing Then Set fd = Nothing
image

Merci bcp cela fonctionne, mais je bloque a la suite, voici mon code adaptée

Dim fd As FileDialog
Dim FileName As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Clear
.Filters.Add "Fichiers Texte", "*.csv"
.Title = "Sélectionnez le document"
.InitialFileName = "C:\Users\Toto\Downloads" & "\order_*.csv"

End With
If fd.Show = True Then FileName = fd.SelectedItems(1)
If Not fd Is Nothing Then Set fd = Nothing

Le fenêtre montre bien que les fichiers demandées, mais la suite de mon code est

4 lignes que j'ai mais en commentaire

'ChDir "D:\Telechargement" 'te place dans le répertoire "TonRep"
'Dim F As Variant
'F = Application.GetOpenFilename("csv Files (order*.csv), order.csv")
'If F = False Then Exit Sub

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & F, Destination _
:=Range("$A$1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

Et Ca plante sur .Refresh BackgroundQuery:=False

Je suppose que c'est par rapport au chargement du fichier qui a été modifé..

Possible d'y remédier ?

Re,

Les quatre lignes, en fait ne servent plus puisque tu passe par Un FileDialog
Pour la suite je ne vois pas suis pas très fort avec PowerQuery, mais tu n'utilise pas la variable FileName donc je ne vois pas l'incidence que cela pourrait avoir.

je viens de voir cela

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & F, Destination _
:=Range("$A$1"))

Ici tu dois changer F par FileName je pense

Bingo, ca marche Merci
Rechercher des sujets similaires à "application getopenfilename filtre nom fichier"