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 :

Macro Excel, Erreur 400/1104


Sujet :

Macros et VBA Excel

  1. #1
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Décembre 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Etudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 17
    Points : 14
    Points
    14
    Par défaut Macro Excel, Erreur 400/1104
    Bonjour,

    lorsque je run le code que je mets ci-dessous, une "erreur 400" apparait (et quand je le lance en modes pas à pas, c'est "erreur 1104").
    J'ai fait le tour des forums parce qu'il y a pas mal de cas similaires, mais je n'arrive toujours pas à trouver mon erreur

    Je joins également en pièce jointe le fichier excel associé.

    Merci de votre aide!!

    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
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    '//============================================================================
    '// COPYRIGHT DASSAULT SYSTEMES 2001
    '//============================================================================
    '// Generative Shape Design
    '// point, splines, loft generation tool
    '//============================================================================
     
    Dim x As Integer
    Dim y As Integer
    Const Cst_iSTARTCurve    As Integer = 1
    Const Cst_iENDCurve      As Integer = 11
    Const Cst_iSTARTLoft     As Integer = 2
    Const Cst_iENDLoft       As Integer = 22
    Const Cst_iSTARTCoord    As Integer = 3
    Const Cst_iENDCoord      As Integer = 33
    Const Cst_iERRORCool     As Integer = 99
    Const Cst_iEND           As Integer = 9999
     
    Const Cst_strSTARTCurve    As String = "StartCurve"
    Const Cst_strENDCurve      As String = "EndCurve"
    Const Cst_strSTARTLoft     As String = "StartLoft"
    Const Cst_strENDLoft       As String = "EndLoft"
    Const Cst_strSTARTCoord    As String = "StartCoord"
    Const Cst_strENDCoord      As String = "EndCoord"
    Const Cst_strEND           As String = "End"
     
     
     
    '------------------------------------------------------------------------
    'To choose the type of profile (1: NACA-64A112
    '2: NACA-64A512
    '------------------------------------------------------------------------
    Function GetProfileType() As Integer
        Dim strInput As String, strMsg As String
     
        choice = 0
        While (choice < 1 Or choice > 2)
            strMsg = "Type in the kind of profile to create  (1 for NACA-64A112, 2 for NACA-64A512):"
     
            strInput = InputBox(Prompt:=strMsg, _
                Title:="Flügel_Schnitt_" & x, XPos:=2000, YPos:=2000)
     
            'Validation of the choice
            choice = CInt(strInput)
            If (choice < 1 Or choice > 2) Then
                MsgBox "Invalid value: must be 1 or 2"
            End If
        Wend
        GetProfileType = choice
    End Function
     
    ''------------------------------------------------------------------------
    ''Get the active cell --- NACA-64A112
    ''------------------------------------------------------------------------
    Function GetCell(iindex As Integer, column As Integer) As String
        Dim Chain As String
     
     
        Sheets("Feuil" & y).Select
        If (column = 1) Then
            Chain = "A" + CStr(iindex)
        ElseIf (column = 2) Then
            Chain = "B" + CStr(iindex)
        ElseIf (column = 3) Then
            Chain = "C" + CStr(iindex)
        End If
        Range(Chain).Select
        GetCell = ActiveCell.Value
    End Function
    Function GetCellA(iRang As Integer) As String
        GetCellA = GetCell(iRang, 1)
    End Function
    Function GetCellB(iRang As Integer) As String
        GetCellB = GetCell(iRang, 2)
    End Function
    Function GetCellC(iRang As Integer) As String
        GetCellC = GetCell(iRang, 3)
    End Function
    '------------------------------------------------------------------------
    'Syntax of the parameter file
    '------------------------
    'StartCurve                 -> to start the list of points defining the spline
    ' double  ,  double  ,  double
    ' double  ,  double  ,  double      -> as many points as necessary to define the spline
    'EndCurve                   -> to end the list of points defining the spline
    '
    '
    'Example:
    '--------
    'StartCurve
    ' -10.89, 10 , 46.78
    '1.56, 4, 6
    'EndCurve  -> spline composed of 2 points
    '------------------------------------------------------------------------
    Sub ChainAnalysis(ByRef iRang As Integer, ByRef x As Double, ByRef y As Double, ByRef Z As Double, ByRef iValid As Integer)
        Dim Chain As String
        Dim Chain2 As String
        Dim Chain3 As String
     
        Chain = GetCellA(iRang)
     
        Select Case Chain
            Case Cst_strSTARTCurve
                iValid = Cst_iSTARTCurve
            Case Cst_strENDCurve
                iValid = Cst_iENDCurve
            Case Cst_strSTARTLoft
                iValid = Cst_iSTARTLoft
            Case Cst_strENDLoft
                iValid = Cst_iENDLoft
            Case Cst_strSTARTCoord
                iValid = Cst_iSTARTCoord
            Case Cst_strENDCoord
                iValid = Cst_iENDCoord
            Case Cst_strEND
                iValid = Cst_iEND
            Case Else
                iValid = 0
        End Select
        If (iValid <> 0) Then
            Exit Sub
        End If
     
     
     
        'Conversion string -> double
        Chain2 = GetCellB(iRang)
        Chain3 = GetCellC(iRang)
        If ((Len(Chain) > 0) And (Len(Chain2) > 0) And (Len(Chain3) > 0)) Then
            x = CDbl(Chain)
            y = CDbl(Chain2)
            Z = CDbl(Chain3)
        Else
            iValid = Cst_iERRORCool
            x = 0#
            y = 0#
            Z = 0#
        End If
    End Sub
     
     
    '------------------------------------------------------------------------
    ' Get CATIA Application
    '------------------------------------------------------------------------
    'Remark:
    '   When KO, update CATIA registers with:
    '                       CNEXT /unregserver
    '                       CNEXT /regserver
    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Function GetCATIA() As Object
        Set CATIA = GetObject(, "CATIA.Application")
        If CATIA Is Nothing Then
           Set CATIA = CreateObject("CATIA.Application")
           CATIA.Visible = True
        End If
     
        Set GetCATIA = CATIA
    End Function
    '------------------------------------------------------------------------
    ' Get CATIADocument
    '------------------------------------------------------------------------
    Function GetCATIAPartDocument() As Object
        Set CATIA = GetCATIA
     
        Dim MyPartDocument As Object
        Set MyPartDocument = CATIA.ActiveDocument
     
        Set GetCATIAPartDocument = MyPartDocument
    End Function
    '------------------------------------------------------------------------
    ' Creates all usable points and splines from the parameter file
    '------------------------------------------------------------------------
    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    'Limitations:
    '   ============================> NO MORE THAN 500 POINTS PER SPLINE
    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Sub CreationSpline()
        'Limitation : points per spline
        Const NBMaxPtParSpline As Integer = 500
     
        'Get CATIA and already created geometrical set
        Dim PtDoc, HKoerper, F, FS As Object
        Set PtDoc = GetCATIAPartDocument
        Set HKoerper = PtDoc.Part.HybridBodies
        Set F = HKoerper.Item("Flügel")
        Set FS = F.HybridBodies.Item("Flügel_Schnitt_" & x)
     
     
     
        'Get the HybridBody and the profile-origin as reference
        Dim Hbody, p, Ref As Object
        Set Hbody = FS.HybridBodies.Item("Profil_Schnitt_" & x)
        Set p = FS.HybridShapes.Item("Ursprung_Schnitt_" & x)
        Set Ref = PtDoc.Part.CreateReferenceFromObject(p)
     
     
        Dim iRang As Integer
        Dim iValid As Integer
        Dim X1 As Double
        Dim Y1 As Double
        Dim Z1 As Double
        Dim index As Integer
        Dim PassingPtArray(1 To NBMaxPtParSpline) As Object
        Dim spline As Object
        Dim ReferenceOnPoint   As Object
        Dim SplineCtrPt As Object
     
     
        iValid = 0
        iRang = 1
        'Analyze file
        While iValid <> Cst_iEND
     
            'reinitialization of point array of the spline
            index = 0
     
     
            'Remove records before StartCurve
            While ((iValid <> Cst_iSTARTCurve) And (iValid <> Cst_iEND))
                ChainAnalysis iRang, X1, Y1, Z1, iValid
                iRang = iRang + 1
            Wend
     
            If (iValid <> Cst_iEND) Then
                'Read until endcurve -> Spline completed
                While ((iValid <> Cst_iENDCurve) And (iValid <> Cst_iEND))
                    ChainAnalysis iRang, X1, Y1, Z1, iValid
                    iRang = iRang + 1
     
     
                    'valid point
                    If (iValid = 0) Then
                        index = index + 1
                        If (index > NBMaxPtParSpline) Then
                            MsgBox "Too many points for a spline. Point deleted"
                        Else
                            Set PassingPtArray(index) = PtDoc.Part.HybridShapeFactory.AddNewPointCoordWithReference(X1, Y1, Z1, Ref)
                            Hbody.AppendHybridShape PassingPtArray(index)
                        End If
                    End If
                Wend
     
     
     
     
                'Start building spline
                'Are there enough points ?
                If (index < 2) Then
                    MsgBox "Not enough points for a spline. Spline deleted"
                Else
                    Set spline = PtDoc.Part.HybridShapeFactory.AddNewSpline
                    spline.SetSplineType 0
                    spline.SetClosing 0
     
     
                    'Creates and adds points to the spline
                    For i = 1 To index
                        Set ReferenceOnPoint = PtDoc.Part.CreateReferenceFromObject(PassingPtArray(i))
                        '    ---- Version Before V5R12
                        ' Set SplineCtrPt = PtDoc.Part.HybridShapeFactory.AddNewControlPoint(ReferenceOnPoint)
                        ' spline.AddControlPoint SplineCtrPt
     
                        '    ---- Since V5R12
                         spline.AddPointWithConstraintExplicit ReferenceOnPoint, Nothing, -1, 1, Nothing, 0
     
                    Next i
     
                    Hbody.AppendHybridShape spline
                End If
            End If
        Wend
     
        PtDoc.Part.Update
    End Sub
     
     
     
     
     
    '------------------------------------------------------------------------
    'Main program
    '------------------------------------------------------------------------
    Sub Main()
     
     
        'Get the type of profile to create:
        '   NACA-64A112        --> 1
        '   NACA-64A512        --> 2
     
     
        For x = 1 To 8
     
        Dim ProfileType As Integer
        ProfileType = GetProfileType
     
     
     
     
        ' V5R12 - Create dedicate openBody for created geometry
        'Get CATIA and already created geometrical set
        Dim PtDoc, HKoerper, F, FS As Object
        Set PtDoc = GetCATIAPartDocument
        Set HKoerper = PtDoc.Part.HybridBodies
        Set F = HKoerper.Item("Flügel")
        Set FS = F.HybridBodies.Item("Flügel_Schnitt_" & x)
     
        ' Create Open body in Geometrical set
        Set Hbody = FS.HybridBodies.Add()
        Hbody.Name = "Profil_Schnitt_" & x
     
        If ProfileType = 1 Then
          y = 1
          CreationSpline
        ElseIf ProfileType = 2 Then
          y = 2
          CreationSpline
        End If
     
     
        Next x
     
     
     
    End Sub
    Fichiers attachés Fichiers attachés

  2. #2
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut
    bonjour,

    sur qu'elle ligne l'erreur ?

  3. #3
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Décembre 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Etudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 17
    Points : 14
    Points
    14
    Par défaut
    Ligne 67!

  4. #4
    Membre expert
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 2 267
    Points : 3 663
    Points
    3 663
    Par défaut
    Bonjour,

    Tu es obligé de sélectionner la cellule lue ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Function GetCell(iindex As Integer, column As Integer) As String
        GetCell = Sheets("Feuil" & y).Cells(iindex, column)
    End Function
    suffit non ?
    Bon, réduit comme ça on se demande si la fonction est vraiment nécessaire, j'ai dû rater qq chose.

    eric

  5. #5
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut
    Citation Envoyé par jbinder Voir le message
    Ligne 67!
    bonjour,

    au moment de l'erreur, actionne le bouton "débogage" puis passe le curseur de ta souris sur la variable chain et dit nous la valeur stockée par cette variable ...


    sinon je suis d'accords avec eriic ce n'est vraiment pas une bonne idée d'abuser des select/activate... et de travailler sans préciser explicitement la feuille et le classeur concerné ... tu ne devrais jamais avoir d'instruction range , cells ... non précédé d'une référence à la feuille de calcul concerné.

  6. #6
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Décembre 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Etudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 17
    Points : 14
    Points
    14
    Par défaut
    En effet
    Merci beaucoup, problème résolu!!!!
    (En fait je m'étais contenté de reprendre la macro fourni avec Catia, qui était d'origine écrit avec ces select et activate)

  7. #7
    Membre expert
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 2 267
    Points : 3 663
    Points
    3 663
    Par défaut
    Re,

    Ils sont bizarres chez Catia ;-)
    Si ça fonctionne comme ça, comme je te disais cette fonction est inutile.
    Tu peux utiliser directement Sheets("Feuil" & y).Cells(iindex, column) sans passer par une fonction personnalisée qui ferait uniquement ça.
    Aucun intérêt, surtout si c'est pour rajouter des erreurs et des cas non traités.

    eric

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

Discussions similaires

  1. [Macro Excel] Erreur d'éxécution 70
    Par kiro4 dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 07/04/2009, 18h46
  2. Erreur 400 après lancement Macro VBA Excel
    Par ananar dans le forum Macros et VBA Excel
    Réponses: 36
    Dernier message: 23/08/2008, 14h33
  3. erreur 1004 macro excel
    Par lerab51 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 04/05/2007, 21h27
  4. Réponses: 9
    Dernier message: 18/09/2006, 11h42
  5. Erreure pendant macro Excel
    Par nemesys971 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 05/01/2006, 12h11

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