Bonjour,
j'ai un petit soucis avec ma macro.
Cette macro, lors de son execution, m'ouvre une fenetre pour sélectionner un fichier (qui ne se nomme jamais pareil).
ensuite ma macro récupère les données qu'il contient.
Mon soucis, c'est que j'aimerais que dans ma macro ce nom de fichier à importer soit variable.
Car là je l'ai mis en dur pour mes tests mais je n'arrive pas à trouver la formule adéquate pour éviter de la mettre en dure.
Sub test()
Dim table() As String
Dim lig As Integer
Dim cl As Range
Dim off1 As Integer
Dim off2 As Integer
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = "C:\"
.Show
If .SelectedItems.Count > 0 Then Workbooks.Open (.SelectedItems(1))
End With
With ActiveWorkbook.Worksheets("Fichiers à importer")
lig = .Columns(1).Find("*", , , , xlByColumns, xlPrevious).row
ReDim table(1 To 5, 1 To lig)
For i = 0 To lig - 1
Set cl = .Range("A1").Offset(i, 0)
off1 = InStr(cl.Value, ";")
table(1, i + 1) = Left(cl.Value, off1 - 1)
For j = 2 To 4
off2 = InStr(off1 + 1, cl.Value, ";")
table(j, i + 1) = Mid(cl.Value, off1 + 1, off2 - off1 - 1)
off1 = off2
Next j
table(5, i + 1) = Right(cl.Value, Len(cl.Value) - off1)
Next i
End With
j'aimerais transformer la ligne With ActiveWorkbook.Worksheets("Fichiers à importer")
pour éviter d'avoir à renommer chaque fichier en "Fichiers à importer".
Est-ce possible ?
Merci d'avance