Envoyer un email selon la langue
Bonjour,
Je dois envoyer un email soit en allemand, soit en français suivant la valeur d'une cellule (FR ou DE).
j'ai voulu utiliser un If... then... mais il ne me reconnaît pas le bloc.
Quelqu'un a une idée svp?
Voici mon code :
Code:
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
| Sub Envoyer()
Dim Chemin As Variant
Dim myApp As Object, myitem As Object, signature As String
Dim Langue As String
Dim sFind
Dim nSearch2 As String
nSearch2 = Range("e3").Value
Langue = "DE"
Chemin = Worksheets("EnvoiDocs").Range("sCS").Offset(0, 3).Value
Set sFind = Sheets("EnvoiDocs").Columns(8).Find(nSearch2, LookIn:=xlValues, MatchCase:=False)
If Not sFind Is Nothing Then
Range(sFind.Address).Name = "sCS"
Range("sCS").Select
End If
If Range("sCS").Offset(0, 3).Value = Langue Then GoTo mailDE
End If
Set myApp = CreateObject("Outlook.Application")
Set myitem = myApp.CreateItem(olMailItem)
With myitem
.Display
End With
signature = myitem.body
With myitem
myitem.Subject = "Envoi d'informations " & Worksheets("EnvoiDocs").Range("sCS").Offset(0, 1).Value
myitem.body = "Bonjour," & _
vbNewLine & signature
myitem.Attachments.Add Chemin
myitem.to = "xxxx.xxxx@xxxx.com"
End With
End Sub |
En enlevant les GoTo, ça marche
Merci pour ton Conseil, j'ai enlever les Goto et j'ai modifié mon code comme tu m'as dis. Ca m'a quand même demandé un Endif que j'ai rajouté au-dessus du Endsud et ça marche parfaitement.
Je redonne mon code modifié, pour ceux qui voudraient s'en inspirer. merci encore pour le coup de main, je bloquais depuis ce matin dessus!
Code:
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
| Sub Envoyer()
Dim Chemin As Variant
Dim myApp As Object, myitem As Object, signature As String
Dim Langue As String
Dim sFind
Dim nSearch2 As String
nSearch2 = Range("e3").Value
Chemin = Worksheets("EnvoiDocs").Range("sCS").Offset(0, 3).Value
Set sFind = Sheets("EnvoiDocs").Columns(8).Find(nSearch2, LookIn:=xlValues, MatchCase:=False)
If Not sFind Is Nothing Then
Range(sFind.Address).Name = "sCS"
Range("sCS").Select
End If
Langue = "DE"
If Range("sCS").Offset(0, 2).Value = Langue Then
Set myApp = CreateObject("Outlook.Application")
Set myitem = myApp.CreateItem(olMailItem)
With myitem
.Display
End With
signature = myitem.body
With myitem
myitem.Subject = "Unterlagen " & Worksheets("EnvoiDocs").Range("sCS").Offset(0, 1).Value
myitem.body = "Guten tag," & _
vbNewLine & signature
myitem.Attachments.Add Chemin
myitem.to = "xxx.xxx@xxx.com"
End With
Else
Set myApp = CreateObject("Outlook.Application")
Set myitem = myApp.CreateItem(olMailItem)
With myitem
.Display
End With
signature = myitem.body
With myitem
myitem.Subject = "Envoi d'informations " & Worksheets("EnvoiDocs").Range("sCS").Offset(0, 1).Value
myitem.body = "Bonjour," & vbCrLf & vbCrLf & "Je vous remercie pour notre conversation au téléphone." & vbCrLf & _
vbCrLf & vbCrLf & "Cordialement," & _
vbNewLine & signature
myitem.Attachments.Add Chemin
myitem.to = "xxxx.xxxx@xxx.com
End With
End If
End Sub |