Ligne de code qui ne fonctionne pas
Bonjour,
Je ne comprends pas pourquoi une seule et unique ne fonctionne pas alors que la syntaxe est identiques au autres :
For j = 2 To Feuil3.Range("A65536").End(xlUp).Row 'je recherche une valeur dans un tableau
If Feuil3.Cells(j, "A").Value = Feuil2.Cells(1, "a").Value Then 'si je la trouve
'je récupère des infos dans certaines cellules et je les colles à l'emplacement de certain signet dans un document 'word
DocWord.Bookmarks("nom_client").Range.Text = Feuil3.Cells(j, "B").Value DocWord.Bookmarks("interlocuteur").Range.Text = Feuil3.Cells(j, "C").Value
DocWord.Bookmarks("adresse").Range.Text = Feuil3.Cells(j, "D").Value
If Feuil3.Cells(j, "E") <> "" Then
DocWord.Bookmarks("adresse2").Range.Text = vbCrLf + Feuil3.Cells(j, "E").Value
Else: DocWord.Bookmarks("adresse2").Range.Text = ""
End If
If Feuil3.Cells(j, "F") <> "" Then
DocWord.Bookmarks("adresse3").Range.Text = vbCrLf + Feuil3.Cells(j, "F").Value
Else: DocWord.Bookmarks("adresse3").Range.Text = ""
End If
If Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M").Value = Feuil3.Cells(2, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "ALLEMAGNE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(3, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "PRINCIPAUTE D'ANDORRE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(4, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "AUTRICHE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(5, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "BELGIQUE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(6, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "BULGARIE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(7, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "CANADA"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(8, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "SUISSE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(9, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "CHINE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(10, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "ESPAGNE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(11, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = ""
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(12, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "PAYS DE GALLES, UK"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(13, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "HONGRIE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(14, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "IRLANDE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(15, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "ITALIE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(16, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "SLOVAQUIE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(17, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "LUXEMBOURG"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(18, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "MARTINIQUE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(19, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "PRINCIPAUTE DE MONACO"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(20, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "POLYNESIE FRANCAISE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(21, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "PORTUGAL"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(22, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "REUNION"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(23, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "ROUMANIE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(24, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "ROYAUME UNI"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(25, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "RUSSIE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(26, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "SLOVENIE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(27, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "TAIWAN"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(28, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "TCHECOSLOVAQUIE"
ElseIf Feuil3.Cells(j, "M") <> "" And Feuil3.Cells(j, "M") = Feuil3.Cells(29, "P").Value Then
DocWord.Bookmarks("pays").Range.Text = "WALES, UK"
End If
DocWord.Bookmarks("code_postal").Range.Text = Feuil3.Cells(j, "G").Value
DocWord.Bookmarks("ville").Range.Text = Feuil3.Cells(j, "H").Value
C'EST ICI QUE CA NE FONCTIONNE PAS : même syntaxe mais en feuil2 ... et ça ne marche pas, si je mets feuil3 ça fonctionne trés bien, si je mets un emplacement précis au lieu de "j" ça fonctionne aussi mais avec j et feuil2 non pourquoi?
DocWord.Bookmarks("liste").Range.Text = Feuil2.Cells(j, "C").Value
End If
Next j
Merci pour l'aide que vous pourriez m'apporter
La feuil2 existe bien, elle est bien reconnue vu que si je mets un chiffre à la place de j cela me retourne bien le texte associé à la cellule dans mon doc word.
Et il me semble que c'est bien du VBA, avec les bibliothèques de compatibilité word et excel pour passer des infos de l'un à l'autre
