iStarOSX
XLDnaute Junior
Bonsoir à tous, j'ai a nouveau un problème auquel je ne trouve pas de solution sur le forum et vois donc a nouveau obligé de faire appel aux expert d'Excel !!!
J'ai un USF dans lequel j'ai un combobox qui détecte les fichiers aux format "CAT_*.txt" dans le sous répertoire de mon classeur "*\Catalogues", grace au code suivant :
En suite avec un bouton je voudrais importer le fichier choisi dans le combobox, mais je n'arrive pas a trouver le bon code :
Et donc je cherche la bonne solution.
Que dois je modifier ?
Si quelqu’un peu m'aider, merci beaucoup.
J'ai un USF dans lequel j'ai un combobox qui détecte les fichiers aux format "CAT_*.txt" dans le sous répertoire de mon classeur "*\Catalogues", grace au code suivant :
Code:
Option Explicit
Dim Chem$
Private Sub Ini()
Dim Chem$, i&, Fs, Nbr&
Chem = ThisWorkbook.Path & "\Catalogues"
Nbr = Len(Chem) + 2
Set Fs = Application.FileSearch
ComboBox1.Clear
With Fs
.LookIn = Chem
.Filename = "CAT_*.txt"
If Fs.Execute > 0 Then
For i = 1 To .FoundFiles.Count
ComboBox1.AddItem Mid(.FoundFiles(i), Nbr)
Next i
Else
MsgBox ("Pas de catalogue de radiateurs")
End If
End With
End Sub
Private Sub UserForm_Activate()
Ini
Chem = ThisWorkbook.Path & "\Catalogues"
If ComboBox1.ListCount > 0 Then ComboBox1.ListIndex = 0
End Sub
En suite avec un bouton je voudrais importer le fichier choisi dans le combobox, mais je n'arrive pas a trouver le bon code :
Code:
Private Sub CommandButton1_Click()
Whem = ThisWorkbook.Path & "\Catalogues"
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Chem & ComboBox1.Value _
, Destination:=Range("A3"))
.Name = ComboBox1.Value
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 2
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Et donc je cherche la bonne solution.
Que dois je modifier ?
Si quelqu’un peu m'aider, merci beaucoup.