IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

extraire les données texte d'un fichier .inf après une [balise]


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Technicien maintenance
    Inscrit en
    Mai 2011
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 2
    Points : 1
    Points
    1
    Par défaut extraire les données texte d'un fichier .inf après une [balise]
    Bonjour,

    je souhaite extraire les données texte d'un fichier .inf après une [balise].

    Concètement, je voudrais extraire les textes qui sont entre les guillemets derrière la balise [Canon] dans l'extrait suivant de mon fichier .inf (ici les modèles d'imprimantes), pour en faire une liste à coller dans des cellules ou dans une listbox.

    Je sais pointer sur le fichier mais pour le reste??

    En VBA ou VB.

    Merci de m'aider.

    [Canon]
    "Canon iR2520 PCL5e" = iR2520,USBPRINT\CanoniR2520_(PCL5e)B22B
    "Canon iR2525/2530 PCL5e" = iR2530,USBPRINT\CanoniR2525/2530_(PC96E9
    "Canon iR2535/2545 PCL5e" = iR2545,USBPRINT\CanoniR2535/2545_(PCBDA4
    "Canon iR-ADV 6055/6065 PCL5e" = iR6065,USBPRINT\CanoniR-ADV_6055/6063CCA
    "Canon iR-ADV 6055/6065-U1 PCL5e" = iRU16A,
    "Canon iR-ADV 6075 PCL5e" = iR6075,USBPRINT\CanoniR-ADV_6075_(PC4BE9
    "Canon iR-ADV 6075-U1 PCL5e" = iRU160,
    "Canon iR-ADV 8085/8095 PCL5e" = iR8095,USBPRINT\CanoniR-ADV_8085/8095FBB
    "Canon iR-ADV 8000s-U1 PCL5e" = iRU180,
    "Canon iR-ADV 8105 PCL5e" = iR8105,USBPRINT\CanoniR-ADV_8105_(PCDAB4
    "Canon iPR1110/1125/1135 PCL5e" = IPR1110,USBPRINT\CanoniPR1110/1125/11B78A
    "Canon iPR Server J100-200 PCL5e" = IPRJ1,
    "Canon iR-ADV C2025 PCL5c" = iRC2025,USBPRINT\CanoniR-ADV_C2025_PC12CE
    "Canon iR C1028/1030 PCL5c" = iRC1030,USBPRINT\CanoniR_C1028/C1030_0E81
    "Canon iR-ADV C2020/2030 PCL5c" = iRC2030,USBPRINT\CanoniR-ADV_C2020/2045DC
    "Canon iR-ADV C2020i/2030i PCL5c" = iRC2030i,USBPRINT\CanoniR-ADV_C2020i/23920
    "Canon iR-ADV C2020L/2030L PCL5c" = iRC2030L,USBPRINT\CanoniR-ADV_C2020L/29E27
    "Canon iR-ADV C5030/5035 PCL5c" = iRC5030,USBPRINT\CanoniR-ADV_C5030/505D1C
    "Canon iR-ADV C5000s-B1 PCL5c" = iRB150,
    "Canon iR-ADV C5045/5051 PCL5c" = iRC5045,USBPRINT\CanoniR-ADV_C5045/505C0D
    "Canon iPR C6010 PCL5c" = iPRC6010,USBPRINT\CanoniPR_C6010_PCL5c34C6
    "Canon iPR C6010VP PCL5c" = iPRC6010VP,USBPRINT\CanoniPR_C6010VP_PCL7009
    "Canon iR-ADV C7000s-A1 PCL5c" = iRA170,
    "Canon iR-ADV C7055/7065 PCL5c" = iRC7055,USBPRINT\CanoniR-ADV_C7055/70EDD7
    "Canon iPR C7010VP PCL5c" = iPRC7010,USBPRINT\CanoniPR_C7010VP_PCL738D
    "Canon iR-ADV C9000s-A1 PCL5c" = iRA190,
    "Canon iR-ADV C9060/9070 PCL5c" = iRC9060,USBPRINT\CanoniR-ADV_C9060/90C872
    "Canon iR-ADV C9065/9075 PCL5c" = iRC9065,USBPRINT\CanoniR-ADV_C9065/909D48
    "Canon MF9200 Series PCL5c" = MF9200,USBPRINT\CanonMF9200_Series_PFDA7
    "Canon LBP6650/3470 PCL5e" = LBP6650,USBPRINT\CanonLBP6650/3470_(P0609
    "Canon LBP6750/3560 PCL5e" = LBP6750,USBPRINT\CanonLBP6750/3560_PC5D7B

    ;WindowsXP
    [Canon.NTx86.5.1]
    "Canon iR2520 PCL5e" = iR2520,USBPRINT\CanoniR2520_(PCL5e)B22B
    "Canon iR2525/2530 PCL5e" = iR2530,USBPRINT\CanoniR2525/2530_(PC96E9
    "Canon iR2535/2545 PCL5e" = iR2545,USBPRINT\CanoniR2535/2545_(PCBDA4
    "Canon iR-ADV 6055/6065 PCL5e" = iR6065,USBPRINT\CanoniR-ADV_6055/6063CCA
    "Canon iR-ADV 6055/6065-U1 PCL5e" = iRU16A,
    "Canon iR-ADV 6075 PCL5e" = iR6075,USBPRINT\CanoniR-ADV_6075_(PC4BE9
    "Canon iR-ADV 6075-U1 PCL5e" = iRU160,
    "Canon iR-ADV 8085/8095 PCL5e" = iR8095,USBPRINT\CanoniR-ADV_8085/8095FBB
    "Canon iR-ADV 8000s-U1 PCL5e" = iRU180,
    "Canon iR-ADV 8105 PCL5e" = iR8105,USBPRINT\CanoniR-ADV_8105_(PCDAB4
    "Canon iPR1110/1125/1135 PCL5e" = IPR1110,USBPRINT\CanoniPR1110/1125/11B78A
    "Canon iPR Server J100-200 PCL5e" = IPRJ1,
    "Canon iR-ADV C2025 PCL5c" = iRC2025,USBPRINT\CanoniR-ADV_C2025_PC12CE
    "Canon iR C1028/1030 PCL5c" = iRC1030,USBPRINT\CanoniR_C1028/C1030_0E81
    "Canon iR-ADV C2020/2030 PCL5c" = iRC2030,USBPRINT\CanoniR-ADV_C2020/2045DC
    "Canon iR-ADV C2020i/2030i PCL5c" = iRC2030i,USBPRINT\CanoniR-ADV_C2020i/23920
    "Canon iR-ADV C2020L/2030L PCL5c" = iRC2030L,USBPRINT\CanoniR-ADV_C2020L/29E27
    "Canon iR-ADV C5030/5035 PCL5c" = iRC5030,USBPRINT\CanoniR-ADV_C5030/505D1C
    "Canon iR-ADV C5000s-B1 PCL5c" = iRB150,
    "Canon iR-ADV C5045/5051 PCL5c" = iRC5045,USBPRINT\CanoniR-ADV_C5045/505C0D
    "Canon iPR C6010 PCL5c" = iPRC6010,USBPRINT\CanoniPR_C6010_PCL5c34C6
    "Canon iPR C6010VP PCL5c" = iPRC6010VP,USBPRINT\CanoniPR_C6010VP_PCL7009
    "Canon iR-ADV C7000s-A1 PCL5c" = iRA170,
    "Canon iR-ADV C7055/7065 PCL5c" = iRC7055,USBPRINT\CanoniR-ADV_C7055/70EDD7
    "Canon iPR C7010VP PCL5c" = iPRC7010,USBPRINT\CanoniPR_C7010VP_PCL738D
    "Canon iR-ADV C9000s-A1 PCL5c" = iRA190,
    "Canon iR-ADV C9060/9070 PCL5c" = iRC9060,USBPRINT\CanoniR-ADV_C9060/90C872
    "Canon iR-ADV C9065/9075 PCL5c" = iRC9065,USBPRINT\CanoniR-ADV_C9065/909D48
    "Canon MF9200 Series PCL5c" = MF9200,USBPRINT\CanonMF9200_Series_PFDA7
    "Canon LBP6650/3470 PCL5e" = LBP6650,USBPRINT\CanonLBP6650/3470_(P0609
    "Canon LBP6750/3560 PCL5e" = LBP6750,USBPRINT\CanonLBP6750/3560_PC5D7B

  2. #2
    Expert éminent
    Homme Profil pro
    Inscrit en
    Août 2010
    Messages
    3 453
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 3 453
    Points : 6 871
    Points
    6 871
    Par défaut
    Bonsoir,

    Pour un premier jet (des adaptations seront à faire par la suite), lancer la proc "Recup" afin de récupérer le fichier sur le disque :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
    Sub Recup()
     
        'lancer cette proc
        Dim Fichier
     
        Fichier = Application.GetOpenFilename("Fichiers inf(*.inf),*.inf", _
                                              1, _
                                              "Fichiers inf")
     
        If Fichier <> False Then
     
            LireFichier Fichier
     
        End If
     
    End Sub
     
    Sub LireFichier(ByVal Fichier As String)
     
        Dim Ligne As String
        Dim I As Integer
        Dim TrouverBalise As Boolean
     
        Open Fichier For Input As #1
     
        Do While Not EOF(1)
     
            Line Input #1, Ligne
     
            'évite la récup des lignes après la seconde balise [Canon.NTx86.5.1]
            'en recherchant le crochet ouvrant dans la ligne
            If InStr(Ligne, "[") Then TrouverBalise = False
     
            'si la balise est trouvée et que ce trouve le mot
            '"Canon" dans la ligne, inscrit en colonne A
            If TrouverBalise And InStr(Ligne, "Canon") <> 0 Then
                I = I + 1
                Range("A" & I) = Ligne
            End If
     
            'si la Balise [Canon] est trouvé
            If Ligne = "[Canon]" Then
                TrouverBalise = True
            End If
     
     
        Loop
     
        Close #1
     
    End Sub
    Hervé.

  3. #3
    Nouveau Candidat au Club
    Profil pro
    Technicien maintenance
    Inscrit en
    Mai 2011
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Bonjour Theze

    merci pour ta réponse, je vais tester ca et je te tiens au courant?

    C'est sympa de ta part.

    Bonne journée.

  4. #4
    Modérateur
    Avatar de AlainTech
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Mai 2005
    Messages
    4 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 70
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2005
    Messages : 4 235
    Points : 24 327
    Points
    24 327
    Par défaut
    Bonjour,

    Pour la lecture/écriture dans des fichiers (de type) .ini, un petit coup d'oeil là
    http://www.vbforums.com/showthread.php?t=349993
    devrait te donner une piste intéressante.
    N'oubliez pas de cliquer sur quand vous avez obtenu ou trouvé vous-même la réponse à votre question.
    Si vous trouvez seul, pensez à poster votre solution. Elle peut servir à d'autres!
    Pensez aussi à voter pour les réponses qui vous ont aidés.
    ------------
    Je dois beaucoup de mes connaissances à mes erreurs!

Discussions similaires

  1. Réponses: 0
    Dernier message: 22/04/2008, 01h24
  2. Extraire des données text d'un fichier *.Res
    Par 130i-24v dans le forum Delphi
    Réponses: 1
    Dernier message: 09/06/2007, 03h05
  3. extraire les données texte d'un fichier .doc
    Par phoenixatareva dans le forum Windows
    Réponses: 2
    Dernier message: 19/04/2007, 15h59
  4. Réponses: 3
    Dernier message: 23/09/2006, 15h19
  5. Pour extraire les données d'un fichier texte
    Par Floch dans le forum Access
    Réponses: 2
    Dernier message: 02/05/2006, 15h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo