Problème de code

apdf1

XLDnaute Impliqué
Bonjour

J'ai problème avec l'envoie de mes pièces jointes, j'ai ce code ci-dessous dans mon module et il me met un message d'erreur:

"Utilisation incorrecte du mot clé Me"


Code:
Public dest As String
Public rn As String
Public nomf As String
Public objet As String
Public corps As String
Public CCdest As String
Sub SendMail_Outlook()
'MJ
'Dim nomf As String
'Avant de lancer cette macro, Dans l'éditeur VBA: Faire Menu / Tools / Reference / Cocher "Microsoft Outlook Library"
'Stop
R = ActiveWorkbook.Path
nomf = ActiveWorkbook.Name
rn = R + "\" + nomf
'Windows("cefichier.xls").Activate
    Sheets("liste").Select
UserForm1.Show
End Sub
Sub lance_outl()
'Adaptation MJ du code trouvé sur http://officeassistant.ibelgique.com/
Dim Ol As New Outlook.Application
Dim Olmail As MailItem
Dim CurrFile As String
'dest = InputBox("destinataire")
Set Ol = New Outlook.Application
Set Olmail = Ol.CreateItem(olMailItem)
'Stop
corps = UserForm1!TextBox3.Text

With Olmail
    '.To = Range("B1").Value
    .To = dest
    .CC = CCdest
    '.Subject = Range("B2").Value
    '.Subject = nomf
    .Subject = objet
    '.Body = Range("B3").Value
        .Body = "Bonjour" & Chr$(10) & corps & Chr$(10) & Chr$(10) & "Cordialement" & Chr$(10) & "Max"
 ''''''   If nomf <> "" Then .Attachments.Add rn '*************** Cette ligne elle sert a attacher le document actif
    '.Attachments.Add "c:\data\essai.doc"

     .To = ListBox1
    .Subject = Me.TextBox2
    .Body = Me.TextBox3
    For i = 0 To Me.ListBox4.ListCount - 1
        .Attachments.Add Me.ListBox4.List(i, 0)
    Next i
'   .Send
    .Display
End With
End Sub

Et ceci dans mon USF.

Code:
Public i As Integer
Public derligne As Integer

Private Sub CommandButton1_Click()

' Message d'oublie
If Me.TextBox2 = "" Then
   MsgBox "Saisissez un sujet !", vbCritical + vbOKOnly, "ATTENTION !"
   Me.TextBox2.SetFocus
   Exit Sub
End If

If Me.ListBox3 = "" Then
   MsgBox "Saisissez un sujet !", vbCritical + vbOKOnly, "ATTENTION !"
   Me.ListBox3.SetFocus
   Exit Sub
End If


    dest = ""
    For i = 0 To derligne - 1
        If ListBox1.Selected(i) = True Then
            
        dest = ListBox1.List(i) & ";" & dest
        End If
        
    Next i
    CCdest = ""
    For j = 0 To derligne - 1
        If ListBox3.Selected(j) = True Then
            
        CCdest = ListBox3.List(j) & ";" & CCdest
        End If
    Next j
    objet = TextBox2.Text
    corps = TextBox3.Text
    UserForm1.Hide
    lance_outl
End Sub
Private Sub OptionButton1_Click()
TextBox2.Text = ""
TextBox3.Text = ""
OptionButton1 = False
End Sub

Private Sub UserForm_Initialize()
TextBox3.MultiLine = True
derligne = ActiveSheet.Range("n65536").End(xlUp).Row
ListBox1.RowSource = "n1:n" & derligne
ListBox3.RowSource = "e1:e" & derligne
End Sub

Private Sub Parcourir_Click()
Dim fd As FileDialog, Tableau
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
With fd
    .AllowMultiSelect = True
    If .Show = -1 Then
        i = 0
        For Each vrtSelectedItem In .SelectedItems
            Tableau = Split(vrtSelectedItem, "\")
            Me.ListBox4.AddItem vrtSelectedItem
            Me.ListBox4.List(i, 1) = Tableau(UBound(Tableau))
            i = i + 1
        Next vrtSelectedItem
    End If
End With
Set fd = Nothing
End Sub

Si quelqu'un pouvais m'aider…….!!
Je vous remercie par avance et vous souhaite une bonne journée

Cordialement

Max
 

Discussions similaires

Réponses
2
Affichages
327
Réponses
6
Affichages
304
Réponses
12
Affichages
508

Statistiques des forums

Discussions
312 613
Messages
2 090 231
Membres
104 453
dernier inscrit
benjiii88