Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2551 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Bug VBA : conversion .txt en .xlsx - Excel redémarre

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Bug VBA : conversion .txt en .xlsx - Excel redémarre

n°2257984
testeuse
Posté le 13-05-2015 à 05:20:31  profilanswer
 

Bonjour,  
je débute en VBA. J'ai besoin d'ouvrir un fichier .txt de le "découper" selon une taille fixe (sans séparateur).
 J'ai un bug, et Excel doit redémarrer. Je suppose que mon bug vient de ma conversion.
 Voici le code au complet et ma fonction principale est "Convertir_GRP_format_117"
 d'avance merci, Testeuse  
Public Format_colonne_117(1 To 3, 1 To 33) As String  
Public Nbre_colonne_format_117 As Integer  
Public Nbre_ligne_fichier_source As Currency  
Public Fichier_2015 As String  
 
 
Sub Sauvegarde_Fermeture_Fichier(NomDuFichier)  
 
' Windows(NomDuFichier).Activate  
' ActiveWorkbook.Save  
Workbooks.Save  
ActiveWindow.Close  
 
End Sub  
 
 
Sub Declaration_format_117() 'Format_colonne_117, Nbre_colonne_format_117  
 
Nbre_colonne_format_117 = 32 '32 colonnes mais tableau de 33 colonnes  
 
Format_colonne_117(1, 1) = "Nom"  
Format_colonne_117(2, 1) = "Debut"  
Format_colonne_117(3, 1) = "Fin"  
 
Format_colonne_117(1, 2) = "Classification"  
Format_colonne_117(2, 2) = 1  
Format_colonne_117(3, 2) = 1  
 
Format_colonne_117(1, 3) = "GHM (Code)" '' ok  
Format_colonne_117(2, 3) = 3  
Format_colonne_117(3, 3) = 1  
 
Format_colonne_117(1, 4) = "Filler"  
Format_colonne_117(2, 4) = 9  
Format_colonne_117(3, 4) = 1  
 
Format_colonne_117(1, 5) = "Format_RSS" ''  
Format_colonne_117(2, 5) = 10  
Format_colonne_117(3, 5) = 1  
 
Format_colonne_117(1, 6) = "Code_retour"  
Format_colonne_117(2, 6) = 13  
Format_colonne_117(3, 6) = 1  
 
Format_colonne_117(1, 7) = "Finess"  
Format_colonne_117(2, 7) = 16  
Format_colonne_117(3, 7) = 1  
 
Format_colonne_117(1, 8) = "Format_RUM"  
Format_colonne_117(2, 8) = 25  
Format_colonne_117(3, 8) = 1  
 
Format_colonne_117(1, 9) = "Numéro de RSS" '' ok  
Format_colonne_117(2, 9) = 28  
Format_colonne_117(3, 9) = 1  
 
Format_colonne_117(1, 10) = "Num_Sej"  
Format_colonne_117(2, 10) = 48  
Format_colonne_117(3, 10) = 1  
 
Format_colonne_117(1, 11) = "Numéro du RUM"  
Format_colonne_117(2, 11) = 68  
Format_colonne_117(3, 11) = 1  
 
Format_colonne_117(1, 12) = "Date_Naiss"  
Format_colonne_117(2, 12) = 78  
Format_colonne_117(3, 12) = 4  
 
Format_colonne_117(1, 13) = "Sexe"  
Format_colonne_117(2, 13) = 86  
Format_colonne_117(3, 13) = 1  
 
Format_colonne_117(1, 14) = "Unité médicale (Code)" '' ok  
Format_colonne_117(2, 14) = 87  
Format_colonne_117(3, 14) = 1  
 
Format_colonne_117(1, 15) = "Type_autorisation"  
Format_colonne_117(2, 15) = 91  
Format_colonne_117(3, 15) = 1  
 
Format_colonne_117(1, 16) = "Date d'entrée" '' ok  
Format_colonne_117(2, 16) = 93  
Format_colonne_117(3, 16) = 4  
 
Format_colonne_117(1, 17) = "Mode d'entrée (Code)" ''  
Format_colonne_117(2, 17) = 101  
Format_colonne_117(3, 17) = 1  
 
Format_colonne_117(1, 18) = "Provenance" ''  
Format_colonne_117(2, 18) = 102  
Format_colonne_117(3, 18) = 1  
 
Format_colonne_117(1, 19) = "Date de sortie" '' ok  
Format_colonne_117(2, 19) = 103  
Format_colonne_117(3, 19) = 4  
 
Format_colonne_117(1, 20) = "Mode de sortie (Code)" ''  
Format_colonne_117(2, 20) = 111  
Format_colonne_117(3, 20) = 1  
 
Format_colonne_117(1, 21) = "Destination" ''  
Format_colonne_117(2, 21) = 112  
Format_colonne_117(3, 21) = 1  
 
Format_colonne_117(1, 22) = "Code_postal"  
Format_colonne_117(2, 22) = 113  
Format_colonne_117(3, 22) = 1  
 
Format_colonne_117(1, 23) = "Poids_nouveau_ne"  
Format_colonne_117(2, 23) = 118  
Format_colonne_117(3, 23) = 1  
 
Format_colonne_117(1, 24) = "Age_gestationnel"  
Format_colonne_117(2, 24) = 122  
Format_colonne_117(3, 24) = 1  
 
Format_colonne_117(1, 25) = "Date_regle"  
Format_colonne_117(2, 25) = 124  
Format_colonne_117(3, 25) = 4  
 
Format_colonne_117(1, 26) = "Nbre_seances" ''  
Format_colonne_117(2, 26) = 132  
Format_colonne_117(3, 26) = 1  
 
Format_colonne_117(1, 27) = "Nbre_DAS"  
Format_colonne_117(2, 27) = 134  
Format_colonne_117(3, 27) = 1  
 
Format_colonne_117(1, 28) = "Nbre_DAD"  
Format_colonne_117(2, 28) = 136  
Format_colonne_117(3, 28) = 1  
 
Format_colonne_117(1, 29) = "Nbre_zone_acte"  
Format_colonne_117(2, 29) = 138  
Format_colonne_117(3, 29) = 1  
 
Format_colonne_117(1, 30) = "Diagnostic principal (Code)" '' ok  
Format_colonne_117(2, 30) = 141  
Format_colonne_117(3, 30) = 1  
 
Format_colonne_117(1, 31) = "DR"  
Format_colonne_117(2, 31) = 149  
Format_colonne_117(3, 31) = 1  
 
Format_colonne_117(1, 32) = "IGS2"  
Format_colonne_117(2, 32) = 157  
Format_colonne_117(3, 32) = 1  
 
Format_colonne_117(1, 33) = "Fin_fichier"  
Format_colonne_117(2, 33) = 160  
Format_colonne_117(3, 33) = 1  
 
End Sub  
 
Sub Calcul_NbreJourneeBrutes(Cell, NbreJourPMSI)  
If NbreJourPMSI = 0 Then  
Cell = 1  
Else  
Cell = NbreJourPMSI  
End If  
End Sub  
 
 
Sub CodeMouvement_Libelle(cell_code, cell_libelle)  
If cell_code >= 1 And cell_code <= 4 Then  
cell_libelle = "Retour prestation"  
ElseIf cell_code = 6 Then  
cell_libelle = "Mutation"  
ElseIf cell_code = 7 Then  
cell_libelle = "Mutation"  
ElseIf cell_code = 8 Then  
cell_libelle = "Domicile"  
ElseIf cell_code = 9 Then  
cell_libelle = "Décès"  
End If  
 
 
End Sub  
 
Sub Declaration_nbre_ligne_fichier_source() 'Nbre_ligne_fichier_source  
Dim i As Long  
 
i = 1  
While Cells(i, 1).Value <> ""  
i = i + 1  
Wend  
 
Nbre_ligne_fichier_source = i - 1  
 
End Sub  
 
 
 
Sub Convertir_GRP_format_117()  
'  
' Convertir_GRP_format_117 Macro  
'  
Dim Fichier_GRP_source As String  
Dim Repertoire_fichier_GRP_source As String  
 
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ''  
'' DECLARATION de variables  
''  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 Fichier_GRP_source = Cells(1, 2).Value  
Fichier_GRP_source_extension = Cells(2, 2).Value  
Repertoire_fichier_GRP_source = Cells(3, 2).Value  
 
Call Declaration_format_117 'Format_colonne_117, Nbre_colonne_format_117  
Fichier_converti = Cells(6, 2).Value 'Fichier_GRP_source & "_converti" 'fichier de l'annee converti
 Repertoire_fichier_converti = Cells(7, 2).Value  
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ''  
'' CONVERTIR GRP au Format 117  
''  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' :=xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _  
 
ChDir Repertoire_fichier_GRP_source  
 
Workbooks.OpenText Filename:= _  
Repertoire_fichier_GRP_source & "\" & Fichier_GRP_source & ".txt", Origin _  
:=xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _  
Array(Format_colonne_117(2, 2) - 1, Format_colonne_117(3, 2)), Array(Format_colonne_117(2, 3) - 1, Format_colonne_117(3, 3)), _
 Array(Format_colonne_117(2, 4) - 1, Format_colonne_117(3, 4)), Array(Format_colonne_117(2, 5) - 1, Format_colonne_117(3, 5)), _
 Array(Format_colonne_117(2, 6) - 1, Format_colonne_117(3, 6)), Array(Format_colonne_117(2, 7) - 1, Format_colonne_117(3, 7)), _
 Array(Format_colonne_117(2, 8) - 1, Format_colonne_117(3, 8)), Array(Format_colonne_117(2, 9) - 1, Format_colonne_117(3, 9)), _
 Array(Format_colonne_117(2, 10) - 1, Format_colonne_117(3, 10)), Array(Format_colonne_117(2, 11) - 1, Format_colonne_117(3, 11)), _
 Array(Format_colonne_117(2, 12) - 1, Format_colonne_117(3, 12)), Array(Format_colonne_117(2, 13) - 1, Format_colonne_117(3, 13)), _
 Array(Format_colonne_117(2, 14) - 1, Format_colonne_117(3, 14)), Array(Format_colonne_117(2, 15) - 1, Format_colonne_117(3, 15)), _
 Array(Format_colonne_117(2, 16) - 1, Format_colonne_117(3, 16)), Array(Format_colonne_117(2, 17) - 1, Format_colonne_117(3, 17)), _
 Array(Format_colonne_117(2, 18) - 1, Format_colonne_117(3, 18)), Array(Format_colonne_117(2, 19) - 1, Format_colonne_117(3, 19)), _
 Array(Format_colonne_117(2, 20) - 1, Format_colonne_117(3, 20)), Array(Format_colonne_117(2, 21) - 1, Format_colonne_117(3, 21)), _
 Array(Format_colonne_117(2, 22) - 1, Format_colonne_117(3, 22)), Array(Format_colonne_117(2, 23) - 1, Format_colonne_117(3, 23)), _
 Array(Format_colonne_117(2, 24) - 1, Format_colonne_117(3, 24)), Array(Format_colonne_117(2, 25) - 1, Format_colonne_117(3, 25)), _
 Array(Format_colonne_117(2, 26) - 1, Format_colonne_117(3, 26)), Array(Format_colonne_117(2, 27) - 1, Format_colonne_117(3, 27)), _
 Array(Format_colonne_117(2, 28) - 1, Format_colonne_117(3, 28)), Array(Format_colonne_117(2, 29) - 1, Format_colonne_117(3, 29)), _
 Array(Format_colonne_117(2, 30) - 1, Format_colonne_117(3, 30)), Array(Format_colonne_117(2, 31) - 1, Format_colonne_117(3, 31)), _
 Array(Format_colonne_117(2, 32) - 1, Format_colonne_117(3, 32)), Array(Format_colonne_117(2, 33) - 1, Format_colonne_117(3, 33)) _
 ), TrailingMinusNumbers:=True  
 
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ''  
'' CREATION du fichier  
''  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 'ActiveWorkbook.SaveAs _ Fichier_converti & ".xlsx" _  
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False  
ActiveWorkbook.SaveAs FileFormat:=xlOpenXMLWorkbook  
 
End Sub

mood
Publicité
Posté le 13-05-2015 à 05:20:31  profilanswer
 

n°2257990
antac
..
Posté le 13-05-2015 à 08:52:28  profilanswer
 

Tu as essayé un débogage pas à pas pour voir où ça coince ?

n°2258096
testeuse
Posté le 14-05-2015 à 00:46:04  profilanswer
 

merci de ton aide,
le problème venait du type des variables utilisées, le code du      workBooks.OpnText aurait dû être :  
 
Workbooks.OpenText Filename:= _  
Repertoire_fichier_GRP_source & "\" & Fichier_GRP_source & ".txt", Origin _  
:=xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _  
Array(CInt(Format_colonne_117(2, 2)) - 1, CInt(Format_colonne_117(3, 2))), Array(CInt(Format_colonne_117(2, 3)) - 1,CInt( Format_colonne_117(3, 3))) _
 ), TrailingMinusNumbers:=True  
 
et mon tableau affectait ainsi :
Format_colonne_117(1, 2) = "Classification"  
Format_colonne_117(2, 2) = "1"  
Format_colonne_117(3, 2) = "1"
 
merci pour tout, tes conseils m'ont été utiles.
 
A bientôt
 

n°2258100
kiki29
Posté le 14-05-2015 à 05:15:23  profilanswer
 

Salut, @testeuse : la moindre des politesses serait de baliser ton code, et pas seulement sur ce forum .....


Message édité par kiki29 le 14-05-2015 à 05:16:13

---------------
Myanmar 90/91 : http://gadaud.gerard.free.fr/publi [...] index.html

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Bug VBA : conversion .txt en .xlsx - Excel redémarre

 

Sujets relatifs
Récupérer valeur dans un tableau avec boucle sous VBAConversion date jjmmaa en jj/mm/aaaa
VBA erreur dépassement de capacité bizarreexportation de graphique d'excel à power point : ne fonctionne qu'une
VBA : Compter le nombre de fichiers PDF dans des sous-dossiersSelection plage de données VBA
Copie coller avec VBA deux fichiers différentsProgramme de Conversion base 10 vers 16 et inversement.
Besoin d'aide Algorithmes VBA 
Plus de sujets relatifs à : Bug VBA : conversion .txt en .xlsx - Excel redémarre


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR