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 :

Probleme de compilation If - End If


Sujet :

Macros et VBA Excel

  1. #1
    Invité
    Invité(e)
    Par défaut Probleme de compilation If - End If
    Bonjour,

    J'ai un soucis avec ce bloc.

    Le programme me signale que mon bloc n'est pas arrêté par un End If.

    Message d'erreur :

    Erreur de compilation :

    Bloc If sans End If
    Pourriez vous m'aider s'il vous plait, car cela ne me saute pas aux yeux.

    Merci.


    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
    Sub Courrier_Word()
     
    Dim mapp As Word.Application
    Dim Mdoc As Word.Document
    Dim Mchemindoc As String
    Dim MRelance As String
     
     
    'ChDrive "G"'
    Mchemindoc = "\\amcristal.local\am\RedirectedFolders\f.nallet\Bureau\Docs\Publipostage\Macro Source\Model Lettre Publi\"
    ChDir Mchemindoc
     
    Set mapp = New Word.Application
     
    If mZAE = True Then
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice Pré-Relance.docx"
    If mZE = True Then
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice Relance.docx"
    If mZE2 = True Then
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice Relance2.docx"
    Else
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice MED.docx"
     
    End If
     
    Set Mdoc = mapp.ActiveDocument
     
    mapp.Visible = True 'Excel screen updating sans desactiver les msgbx utilisable que pdt pilotage
    mapp.Options.ReplaceSelection = False 'Mode refrappe par defaut d'ou False pour desactiver
    mapp.Selection.HomeKey unit:=wdStory 'positionnement haut doc
     
    If mZAE = True Then
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Nomcli_AE"
                If MNomCli <> "0" Then mapp.Selection.TypeText Text:=MNomCli
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr1_AE"
                If MAdr1 <> "0" Then mapp.Selection.TypeText Text:=MAdr1
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr2_AE"
                If MAdr2 <> "0" Then mapp.Selection.TypeText Text:=MAdr2
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="CPCity_AE"
                If MCPCity <> "0" Then mapp.Selection.TypeText Text:=MCPCity
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Country_AE"
                If MCountry <> "0" Then mapp.Selection.TypeText Text:=MCountry
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Echeance_AE"
                If MdateEch <> "0" Then mapp.Selection.TypeText Text:=MdateEch
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Collector_AE"
                If MCollector <> "0" Then mapp.Selection.TypeText Text:=MCollector
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Tel_AE"
                If MTel <> "0" Then mapp.Selection.TypeText Text:=MTel
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Fax_AE"
                If MFax <> "0" Then mapp.Selection.TypeText Text:=MFax
     
    If mZE = True Then
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Nomcli_E"
                If MNomCli <> "0" Then mapp.Selection.TypeText Text:=MNomCli
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr1_E"
                If MAdr1 <> "0" Then mapp.Selection.TypeText Text:=MAdr1
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr2_E"
                If MAdr2 <> "0" Then mapp.Selection.TypeText Text:=MAdr2
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="CPCity_E"
                If MCPCity <> "0" Then mapp.Selection.TypeText Text:=MCPCity
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Country_E"
                If MCountry <> "0" Then mapp.Selection.TypeText Text:=MCountry
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Collector_E"
                If MCollector <> "0" Then mapp.Selection.TypeText Text:=MCollector
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Tel_E"
                If MTel <> "0" Then mapp.Selection.TypeText Text:=MTel
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Fax_E"
                If MFax <> "0" Then mapp.Selection.TypeText Text:=MFax
     
    If mZE2 = True Then
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Nomcli_E"
                If MNomCli <> "0" Then mapp.Selection.TypeText Text:=MNomCli
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr1_E"
                If MAdr1 <> "0" Then mapp.Selection.TypeText Text:=MAdr1
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr2_E"
                If MAdr2 <> "0" Then mapp.Selection.TypeText Text:=MAdr2
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="CPCity_E"
                If MCPCity <> "0" Then mapp.Selection.TypeText Text:=MCPCity
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Country_E"
                If MCountry <> "0" Then mapp.Selection.TypeText Text:=MCountry
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Collector_E"
                If MCollector <> "0" Then mapp.Selection.TypeText Text:=MCollector
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Tel_E"
                If MTel <> "0" Then mapp.Selection.TypeText Text:=MTel
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Fax_E"
                If MFax <> "0" Then mapp.Selection.TypeText Text:=MFax
     
    Else
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Nomcli_E"
                If MNomCli <> "0" Then mapp.Selection.TypeText Text:=MNomCli
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr1_E"
                If MAdr1 <> "0" Then mapp.Selection.TypeText Text:=MAdr1
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr2_E"
                If MAdr2 <> "0" Then mapp.Selection.TypeText Text:=MAdr2
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="CPCity_E"
                If MCPCity <> "0" Then mapp.Selection.TypeText Text:=MCPCity
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Country_E"
                If MCountry <> "0" Then mapp.Selection.TypeText Text:=MCountry
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Collector_E"
                If MCollector <> "0" Then mapp.Selection.TypeText Text:=MCollector
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Tel_E"
                If MTel <> "0" Then mapp.Selection.TypeText Text:=MTel
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Fax_E"
                If MFax <> "0" Then mapp.Selection.TypeText Text:=MFax
     
    End If
     
    'si pas de variable rattaché = mapp.selection.typetext text:="blablabal"
     
        Mdoc.PrintOut
     
    Mdoc.Close SaveChanges:=wdDoNotSaveChanges
     
    'dans le cas de sauvegarde reseau Mdoc.saveas filename:= "G:\...
    'Mdoc.Close
     
     
    mapp.Quit 'necessité de fermé tous les docs avant de quitter.
     
    'decharger la memoire
    Set Mdoc = Nothing
    Set mapp = Nothing
     
    End Sub
    Dernière modification par LittleWhite ; 22/08/2016 à 17h21. Motif: Balises quote

  2. #2
    Membre Expert
    Homme Profil pro
    PAO
    Inscrit en
    Octobre 2014
    Messages
    2 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : PAO
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2014
    Messages : 2 576
    Par défaut
    Bonjour,
    Après le 1er If, les 2 suivants ne sont pas If mais ElseIf
    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
    Sub Courrier_Word()
     
    Dim mapp As Word.Application
    Dim Mdoc As Word.Document
    Dim Mchemindoc As String
    Dim MRelance As String
     
     
    'ChDrive "G"'
    Mchemindoc = "\\amcristal.local\am\RedirectedFolders\f.nallet\Bureau\Docs\Publipostage\Macro Source\Model Lettre Publi\"
    ChDir Mchemindoc
     
    Set mapp = New Word.Application
     
    If mZAE = True Then
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice Pré-Relance.docx"
    ElseIf mZE = True Then
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice Relance.docx"
    ElseIf mZE2 = True Then
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice Relance2.docx"
    Else
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice MED.docx"
     
    End If
     
    …
    il faut revoir ta gestion des If
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    If la_Condition then
       code
    ElseIf la_Condition then
       code
    Else
       Code
    End if
    Sur une ligne (déconseillé):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If la_Condition then code Else If la_Condition then code Else code
    regardes bien les différences
    voilà à toi de vérifier sur l'ensemble de ton code
    Cordialement
    Ryu

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. – Albert Einstein

    Pensez à la Balise [ CODE][/CODE ] - à utiliser via le bouton # => Exemple

    Une fois votre problème solutionné pensez à mettre :resolu: en n'oubliant pas d'indiquer qu'elle est la solution finale choisie ;)

  3. #3
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    je suis pas sur d'avoir tous compris,de plus j'ai pas tout regardé, mais il ne me semble pas utile d'utiliser de Elseif!

    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
    If mZAE = True Then mapp.Documents.Open Filename:=Mchemindoc & "Matrice Pré-Relance.docx"
    If mZE = True Then mapp.Documents.Open Filename:=Mchemindoc & "Matrice Relance.docx"
    If mZE2 = True Then
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice Relance2.docx"
    Else
            mapp.Documents.Open Filename:=Mchemindoc & "Matrice MED.docx"
     
    End If
     
    Set Mdoc = mapp.ActiveDocument
     
    mapp.Visible = True 'Excel screen updating sans desactiver les msgbx utilisable que pdt pilotage
    mapp.Options.ReplaceSelection = False 'Mode refrappe par defaut d'ou False pour desactiver
    mapp.Selection.HomeKey unit:=wdStory 'positionnement haut doc
     
    If mZAE = True Then
            mapp.Selection.Goto what:=wdGoToBookmark, Name:="Nomcli_AE"
                If MNomCli <> "0" Then mapp.Selection.TypeText Text:=MNomCli: mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr1_AE"
                If MAdr1 <> "0" Then mapp.Selection.TypeText Text:=MAdr1: mapp.Selection.Goto what:=wdGoToBookmark, Name:="Adr2_AE"
                If MAdr2 <> "0" Then mapp.Selection.TypeText Text:=MAdr2: mapp.Selection.Goto what:=wdGoToBookmark, Name:="CPCity_AE"
                If MCPCity <> "0" Then mapp.Selection.TypeText Text:=MCPCity: mapp.Selection.Goto what:=wdGoToBookmark, Name:="Country_AE"
                If MCountry <> "0" Then mapp.Selection.TypeText Text:=MCountry: mapp.Selection.Goto what:=wdGoToBookmark, Name:="Echeance_AE"
                If MdateEch <> "0" Then mapp.Selection.TypeText Text:=MdateEch: mapp.Selection.Goto what:=wdGoToBookmark, Name:="Collector_AE"
                If MCollector <> "0" Then mapp.Selection.TypeText Text:=MCollector: mapp.Selection.Goto what:=wdGoToBookmark, Name:="Tel_AE"
                If MTel <> "0" Then mapp.Selection.TypeText Text:=MTel: mapp.Selection.Goto what:=wdGoToBookmark, Name:="Fax_AE"
                If MFax <> "0" Then mapp.Selection.TypeText Text:=MFax
    End If

  4. #4
    Invité
    Invité(e)
    Par défaut
    Merci a vous pour vos réponses.

    Il fallait bien remplacer les deux If par ElseIf.

    Bonne journée.

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

Discussions similaires

  1. [API][Cup] problem niveau compilation
    Par KoLziG dans le forum Général Java
    Réponses: 1
    Dernier message: 02/01/2005, 19h30
  2. [JSP & TAGLIB] Probleme de compilation
    Par GesMo dans le forum Servlets/JSP
    Réponses: 7
    Dernier message: 17/05/2004, 15h03
  3. Probleme de Compilation de la STL
    Par stoluup dans le forum MFC
    Réponses: 3
    Dernier message: 05/05/2004, 17h25
  4. [TP]Probleme de compilation sous TP7
    Par yffick dans le forum Turbo Pascal
    Réponses: 7
    Dernier message: 18/12/2003, 20h32
  5. Problemes de compilation avec g++ sous linux
    Par Selimmel dans le forum Autres éditeurs
    Réponses: 3
    Dernier message: 19/09/2003, 13h43

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