Ouvrir fichier txt contenant un mot

sweatjoe

XLDnaute Nouveau
Bonsoir le forum,

Je cherche a créer une macro qui me permettrai d'ouvrir un fichier TXT contenant le mot "DIR" dans le nom du fichier. Ce fichier se trouve dans le même dossier parmis plein d'autres fichiers. Attention, le mot DIR pourra se situer aussi bien au début, au milieux ou à la fin du nom du fichier.
Merci beaucoup pour votre aide.

Cdt,

Sweatjoe
 
Dernière édition:

JCGL

XLDnaute Barbatruc
Re : Ouvrir fichier txt contenant un mot

Bonjour à tous,

Peux-tu essayer ceci :

VB:
Option Explicit


Sub Test()
    On Error Resume Next
    Workbooks.OpenText Filename:=ThisWorkbook.Path & "\" & "*DIR.txt", Origin _
    :=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, Tab:=True
    Workbooks.OpenText Filename:=ThisWorkbook.Path & "\" & "*DIR*.txt", Origin _
    :=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, Tab:=True
    Workbooks.OpenText Filename:=ThisWorkbook.Path & "\" & "DIR*.txt", Origin _
    :=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, Tab:=True
End Sub

A + à tous
 

Discussions similaires