Probléme de syntaxe vba pour importation fichier avec condition nom du fichier
Bonjour,
Je souhaite importer des fichiers txt automatiquement selon leur nom qui commence par une variable fournie par l'utilisateur.
Chaque jour, des fichiers txt sont créés avec dans leur nom la date du jour ex: G10220118205627.txt
Je passe donc par une Inputbox pour récuperer une valeur fournie par l'utilisateur, mais mon script ne reconnaît pas "MyValue" dans la condition.
Voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
' importation auto de tous les fichiers text du répertoire guardians selon datej
Public Sub ImportDj()
Dim FileName, FilePathName, Path, FileNamelist() As String
Dim FileCount As Integer
Dim Message, Title, Default, MyValue
Message = "Début du nom de fichier"
Title = "Variable extraction"
Default = "G10220118"
MyValue = InputBox(Message, Title, Default)
DoCmd.SetWarnings False
Path = "W:\FTP\RSFLERS\rapport_guardian2\"
FileName = Dir(Path & "")
While FileName <> "" And Right(FileName, 3) = "txt" And Left(FileName, 9) = "MyValue"
FileCount = FileCount + 1
ReDim Preserve FileNamelist(1 To FileCount)
FileNamelist(FileCount) = FileName
FileName = Dir()
Wend
If FileCount > 0 Then
For FileCount = 1 To UBound(FileNamelist)
FilePathName = Path & FileNamelist(FileCount)
DoCmd.TransferText transferType:=acImportDelim, SpecificationName:="SpeImport", TableName:=FileNamelist(FileCount), FileName:=FilePathName, hasfieldnames:=False
Next
End If
DoCmd.SetWarnings True
MsgBox ("terminé !")
End Sub |
Merci de votre aide.