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 53 54 55 56 57 58 59 60 61 62 63 64
| Dim LeFichierAOuvrir As String
Public Sub OuvrirJournaux()
Dim nomfeuille As String, Ligne As String, fichier1 As String, texte As String, _
tableau() As String, i As Long, n As Long, compteur As Long, a As Range, x As Long, dl As Long, ir As Integer, _
firstaddress As String, nomfeuille1 As String, nomfeuille2 As String, irow As Integer, nomfichier As String
'On Error GoTo GestionErreur1
ouvert = 0
Workbooks.OpenText Filename:=LeFichierAOuvrir, Origin:=xlWindows, StartRow _
:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 2), Array(3, 2), Array( _
6, 2), Array(9, 2), Array(44, 2), Array(47, 2), Array(50, 2), Array(53, 2), Array(70, 2), _
Array(73, 2), Array(76, 2), Array(276, 2), Array(476, 2), Array(493, 2), Array(494, 2), _
Array(495, 2), Array(512, 2), Array(513, 2), Array(514, 2))
ouvert = 1 'si le fichier est ouvert sous forme de classeur XLS
Set NomDuFichierOuvert = ActiveWorkbook
nomfichier = ActiveWorkbook.Name
'enregistrement du nom de la feuille active dans une variable
nomfeuille = ActiveSheet.Name
'recherche de la valeur 'CAE' dans la colonne 'b'
With Sheets(nomfeuille)
dl = .Range("b" & Rows.Count).End(xlUp).Row
Set a = .Range("B1:B" & dl).Find("JAL")
'Emepeche le rafraichissement de l'écran, pour ne pas voir le traitement
Application.ScreenUpdating = False
If Not a Is Nothing Then
'création d'une nouvelle feuille et on l'a renomme
Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Journaux"
Sheets(nomfeuille).Select
firstaddress = a.Address
irow = 0
'copie des lignes concerner
Do While Not a Is Nothing
irow = irow + 1
Sheets("Journaux").Cells(irow, 1).Columns("A:BP").Value = a.EntireRow.Value
Set a = .Range("B" & a.Row, "B" & dl).Find("JAL")
If a.Address = firstaddress Then
Exit Do
End If
If a Is Nothing Then
Exit Do
End If
firstaddress = a.Address
Loop
End If
Sheets("Journaux").Select
Call LigneChampsJnal
End With
'copie de la feuille du nouveau classeur dans l'ancien et suppresion du nouveau
Application.DisplayAlerts = False
Sheets("Journaux").Select
Sheets("Journaux").Copy After:=Workbooks("Essai.xls").Sheets(1)
Windows(nomfichier).Close
Windows("Essai.xls").Activate
Application.DisplayAlerts = True
Exit Sub
End Sub
Public Sub ImporterJnal()
Application.ScreenUpdating = False
LeFichierAOuvrir = Application.GetOpenFilename(Title:="Nom du fichier PGI à ouvrir")
If LeFichierAOuvrir <> "Faux" Then
OuvrirJournaux
End If
Application.ScreenUpdating = True
End Sub |
Partager