VBA en VBS

olisab1 Messages postés 12 Date d'inscription dimanche 1 juillet 2007 Statut Membre Dernière intervention 4 juillet 2012 - 20 janv. 2008 à 14:03
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 20 janv. 2008 à 14:34
Bonjour

J'ai ce code en vba que j"aimerais compiler en vbs.
Merci par avance pour l'aide que vous pourrez m'apporter.

Private Sub workbook_open()

' Déclarations des variables : il vaut mieux le faire, cela facilite la compréhension ! et c'est plus propre
Dim Tableau_Ligne(200) As String   ' Permet de stocker 200 lignes de texte
Dim Nfich, Nfich1 As String                 ' Nom du fichier avant et après modif
Dim fich As String                                 ' Pour parcourir le répertoire
Dim Chemin As String                        ' Répertoire à parcourir
Dim compteur As Integer                   ' compteur du nombre de lignes lues
Dim position As Integer                     ' valeur de l'indice du tableau où il y a la ligne NOM_GEX
Dim i As Integer    ' variable pour dérouler une boucle

Application.OnTime Now + TimeValue("00:00:5"), "Quitter"

Chemin = "J:\sesame\remontees_standard\CE\A7A8\mont\CE\*.txt"
fich = Dir(Chemin)
SuiteFich:
Nfich = "J:\sesame\remontees_standard\CE\A7A8\mont\CE" & fich
Nfich1 = "J:\sesame\remontees_standard\CE\A7A8\mont\CE" & fich & "1"
DateFich = Mid(fich, Len(fich) - 18, Len(fich) - 4)
Open Nfich For Input As #1
Open Nfich1 For Output As #2
compteur = 0    ' initialisation du compter, à ne pas oublier !
Do While Not EOF(1)
Rem ' Boucle de lecture du fichier, jusqu'à ce qu'on ait rencontré NUM_OF
Line Input #1, ligne
' Teste si la ligne lue pour savoir si elle commence par NOM_GEX
    If Left(ligne, 7) = "NOM_GEX" Then
'          oui => on stocke dans une variable le compteur actuel pour pouvoir modifier la ligne plus tard
position = compteur
End If
' Teste si la ligne lue commence par NUM_OF
   If Left(ligne, 9) = "REP_PIECE" Then
'             oui => on regarde si c'est rep piece A ou rep piece B

   If Right(ligne, 1) = "A" Then
'             cas montage A => on rajoute montage A à la ligne NOM_GEX si celle-ci contient 1119976_xBxxG_xxxxxxxxxx
'
'             CU01
'
               If Tableau_Ligne(position) Like "*1119971_xBxxD_xxxxxxxxxx" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_xBxxD_xxmontageA"   ' on modifie la ligne stockée
               End If
               If Tableau_Ligne(position) Like "*1119971_XBXXD_XXXXXXXXXX" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_XBXXD_XXMONTAGEA"   ' on modifie la ligne stockée
               End If
                           
               If Tableau_Ligne(position) Like "*1119971_xBxxG_xxxxxxxxxx" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_xBxxG_xxmontageA"   ' on modifie la ligne stockée
               End If
               If Tableau_Ligne(position) Like "*1119971_XBXXG_XXXXXXXXXX" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_XBXXG_XXMONTAGEA"   ' on modifie la ligne stockée
               End If
              
               If Tableau_Ligne(position) Like "*1119971_xHxxD_xxxxxxxxxx" Then
                  Tableau_Ligne(position) = "NOM_GEX, 1119971_xHxxD_xxmontageA"   ' on modifie la ligne stockée
               End If
               If Tableau_Ligne(position) Like "*1119971_XHXXD_XXXXXXXXXX" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_XHXXD_XXMONTAGEA"   ' on modifie la ligne stockée
               End If
                            
               If Tableau_Ligne(position) Like "*1119971_xHxxG_xxxxxxxxxx" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_xHxxG_xxmontageA"   ' on modifie la ligne stockée
               End If
               If Tableau_Ligne(position) Like "*1119971_XHXXG_XXXXXXXXXX" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_XHXXG_XXMONTAGEA"   ' on modifie la ligne stockée
               End If
                      
                                 
        End If
        
         If Right(ligne, 1) = "B" Then
 '             cas montage B => on rajoute montage B à la ligne NOM_GEX si celle-ci contient 1119976_xBxxG_xxxxxxxxxx
              
              CU01
 
               If Tableau_Ligne(position) Like "*1119971_xBxxD_xxxxxxxxxx" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_xBxxD_xxmontageB"   ' on modifie la ligne stockée
               End If
               If Tableau_Ligne(position) Like "*1119971_XBXXD_XXXXXXXXXX" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_XBXXD_XXMONTAGEB"   ' on modifie la ligne stockée
               End If
            
               If Tableau_Ligne(position) Like "*1119971_xBxxG_xxxxxxxxxx" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_xBxxG_xxmontageB"   ' on modifie la ligne stockée
               End If
               If Tableau_Ligne(position) Like "*1119971_XBXXG_XXXXXXXXXX" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_XBXXG_XXMONTAGEB"   ' on modifie la ligne stockée
               End If
              
               If Tableau_Ligne(position) Like "*1119971_xHxxD_xxxxxxxxxx" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_xHxxD_xxmontageB"   ' on modifie la ligne stockée
               End If
               If Tableau_Ligne(position) Like "*1119971_XHXXD_XXXXXXXXXX" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_XHXXD_XXMONTAGEB"   ' on modifie la ligne stockée
               End If
                            
               If Tableau_Ligne(position) Like "*1119971_xHxxG_xxxxxxxxxx" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_xHxxG_xxmontageB"   ' on modifie la ligne stockée
               End If
               If Tableau_Ligne(position) Like "*1119971_XHXXG_XXXXXXXXXX" Then
                   Tableau_Ligne(position) = "NOM_GEX, 1119971_XHXXG_XXMONTAGEB"   ' on modifie la ligne stockée
               End If
                                    
              
         End If
 ' maintenant, on écrit dans le fichier de sortie toutes les lignes stockées dans le tableau, sans oublier bien sûr la ligne
 ' NUM_OF en cours de traitement
         For j = 0 To compteur - 1
              Print #2, Tableau_Ligne(j)
        Next j
        Print #2, ligne
        Exit Do    ' et sortie de la boucle de lecture du fichier
      Else
 ' pas dans le cas NUM_OF, on stocke la ligne dans le tableau
        Tableau_Ligne(compteur) = ligne   ' on stocke la ligne lue
       compteur = compteur + 1    ' on incrémente le compteur pour la prochaine ligne !
   End If
 Loop   ' Fin de la boucle de lecture jusqu'à NUM_OF
 Do While Not EOF(1)
 ' Boucle de lecture du reste du fichier, jusqu'à la fin
   Line Input #1, ligne
   Print #2, ligne    ' écriture directe, aucun test à faire puisque l'essentiel est déjà fait !
 Loop
Close #1
Close #2
fich = Dir
If fich <> "" Then GoTo SuiteFich
Application.DisplayAlerts = False
Application.Quit
End Sub

1 réponse

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
20 janv. 2008 à 14:34
 Bonjour à tous,

Bonjour Olisab1,

En disséquant les 2 scripts (question/réponse) de ton prédécent post, tu as tous les éléments
pour translater ce nouveau code.
http://www.vbfrance.com/infomsg_VBA-VBS_1057067.aspx

Il y a similitude dans tes 2 scripts vba, donc, avance dans ta translation
Et si problème, pose une question précise.

jean-marc
0
Rejoignez-nous