UserForm / Outlook
Bonjour,
Je n'ai pas une grande expérience en VBA et je fais face à un problème. J'ai crée un UserForm où l'utilisateur peut rentrer certaines informations manuellement, et j'aimerai à partir de cet UserForm une fois remplit, que ma macro génère un mail via Outlook. Voici ma macro si vous avez des indices :
Private Sub CommandButton1_Click ()
Dim Confirmation
Confirmation = MsgBox ("xxxxxx")
If Confirmation = vbNo Then
Exit Sub
ElseIf Confirmation = vbYes Then
Exit Sub
Dim OutApp As Object
Dim OutMail As Object
Dim corps As String
Set OutApp = CreateObject ("Outlook.Application")
Set OutMail = OutApp.CreateItem (0)
OutMail.Subject = "xxx"
corps = "xxx"
corps = corps & Chr(13) & Chr(10)
corps = "xxxx" & Chr(13) & Chr(10)
corps = corps & UserForm1.TextBox1.Value
corps = corps & UserForm1.TextBox2.Value
corps = "xxxx"
OutMail.body = corps
Set OutMail = Nothing
Set OutApp = Nothing
End If
End Sub
Mon Userform s'affiche je peux le remplir mais le mail ne se génère jamais.
Merci d'avance.
Bonjour,
If Confirmation = vbNo Then
Exit Sub
ElseIf Confirmation = vbYes Then
Exit Sub
en ajoutant un 3ème bouton 'peut-être' ça lui laissera une chance de passer...
Au passage ton elseif est inutile. Sur une boite à 2 boutons si la réponse n'est pas la 1ère c'est obligatoirement la 2nde.
Inutile de tester quoique ce soit
eric
Bonjour,
Merci de ta réponse, j'ai rajouté un troisième bouton mais rien à faire le mail ne se génère pas, aurait-tu d'autres pistes ?
Private Sub CommandButton1_Click()
Dim Confirmation
Confirmation = MsgBox("Êtes-vous sûr de vouloir envoyer votre demande", vbYesNoCancel, "Attention!")
If Confirmation = vbNo Then
Exit Sub
ElseIf Confirmation = vbCancel Then
Exit Sub
ElseIf Confirmation = vbYes Then
Exit Sub
Dim OutApp As Object
Dim OutMail As Object
Dim corps As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
OutMail.Subject = "Request for missing documents"
corps = "Hello, "
corps = corps & Chr(13) & Chr(10)
corps = "For the below entity :" & Chr(13) & Chr(10)
corps = corps & UserForm1.TextBox1.Value & Chr(13) & Chr(10)
corps = corps & UserForm1.TextBox2.Value & Chr(13) & Chr(10)
corps = "Could you please sent us the missing followinfg documents :"
OutMail.Body = corps
Set OutMail = Nothing
Set OutApp = Nothing
End If
End Sub
Bonjour,
c'était une blague le 3ème bouton.
Si tu en met 10 avec exit sub sur tous ça sera toujours pareil.
Un pour quitter, l'autre il faut laisser passer.
Pour programmer il faut un minimum de logique et déjà connaitre les bases. Tu ferais bien de parcourir les cours pour débutants. Voir menu Cours VBA en haut.
If MsgBox("Êtes-vous sûr de vouloir envoyer votre demande", vbYesNo, "Attention!")=vbNo Then Exit Sub
' suite du programme
eric
Merci, j'ai réussi. Je n'avais pas noté la pointe d'humour...