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 :

Bug VBA : conversion .txt en .xlsx - Excel redémarre [XL-2007]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Femme Profil pro
    chargé d'études
    Inscrit en
    Mai 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : chargé d'études

    Informations forums :
    Inscription : Mai 2015
    Messages : 2
    Par défaut Bug VBA : conversion .txt en .xlsx - Excel redémarre
    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, Tes_teuse

    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
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    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

  2. #2
    Membre Expert
    Avatar de Igloobel
    Homme Profil pro
    Développeur ERP - VBA et Formateur bureautique
    Inscrit en
    Septembre 2005
    Messages
    1 871
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Développeur ERP - VBA et Formateur bureautique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 871
    Billets dans le blog
    1
    Par défaut
    Bonjour,

    bon déjà sans aller plus loin il y a des choses qui vont pas

    d'abord met ton code entre les balises code #

    ensuite ton code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Format_colonne_117(1, 3) = "GHM (Code)" '' ok
    ne doit pas marcher car tu as 3 "

    et pour tous les chiffres que tu affectes dans ton tableau, là il faut mettre des guillements parce que tu déclares ton tableau en texte
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    ' tu mets ceci 
    Format_colonne_117(2, 3) = 3 
    ' il faut cela
    Format_colonne_117(2, 3) = "3"
    sinon tu peux rempalcer ton code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    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
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    derl = ActiveCell.End(xlDown).Row
    déjà fait ça et on verra la suite après

  3. #3
    Candidat au Club
    Femme Profil pro
    chargé d'études
    Inscrit en
    Mai 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : chargé d'études

    Informations forums :
    Inscription : Mai 2015
    Messages : 2
    Par défaut Mille mercis
    Bonjour Igloobel,

    Je te remercie de tes conseils et de ta rapidité.

    Le problème venait bien du WorkBooks.OpenText (je m'en doutais bien que Excel convertissait le fichier car je le voyais).
    Je manque de rigueur entre le type de mes variables déclarées et la données que je leur affecte.

    Au plaisir de te re-lire (corrigeant mes erreurs!)
    Pour un premier topic, je suis très contente.

    A bientôt,
    Tes-teuse

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 12/03/2015, 13h54
  2. conversion .txt en excel puis traitements automatisés
    Par phil164 dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 25/05/2007, 20h05
  3. Réponses: 5
    Dernier message: 30/08/2006, 15h10
  4. [VBA] Conversion de texte en lien hyperlink sous Excel
    Par logica dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 22/06/2006, 14h10
  5. [VBA-E] Exporter une page Excel vers un Fichier Txt
    Par mamantins dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 08/06/2006, 11h09

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