Adaptation code pour envoi d'un message avec Lotus Note 6.5

brunounours

XLDnaute Nouveau
Bonjour,

Je souhaiterai envoyer un message utilisant une macro à travers LotusNote:

Voila mon point de départ:

Access - Les Sources

j'ai créé un bouton pour lancer la procedure qui possède ce code:

Code:
Private Sub CommandButton1_Click()

SendNotesMail Me!txtSubject, Me!txtAttachment, Me!txtTo, _
                Me!txtCC, Me!txtCCC, Me!txtMessage, False

End Sub

Voila la tentative d'adaptation que j'ai essayé de faire:

Code:
Public Sub SendNotesMail(ByVal Subject As String, _
ByVal Attachment As String, ByVal RECIPIENT As String, _
ByVal CC As String, ByVal BCC As String, _
ByVal BodyText As String, ByVal SaveIt As Boolean)

Dim oMaildb As Object
Dim oMailDoc As Object
Dim oAttachME As Object
Dim oSession As Object
Dim oEmbedObj As Object
    
Dim sUserName As String
Dim sMailDbName As String

Const STR_ATTACHMENT As String = "Attachment"
    
On Error GoTo L_ErrCannotCreateNotesSession
    Set oSession = CreateObject("Notes.NotesSession")
    sUserName = oSession.sUserName
    sMailDbName = Left$(sUserName, 1) & Right$(sUserName, _
         (Len(sUserName) - InStr(1, sUserName, " "))) & ".nsf"
    DoEvents
    lblStatus.Caption = "Information about sender..."
    Call Sleep(1000)
    Set oMaildb = oSession.GETDATABASE(vbNullString, _
             sMailDbName)
     If oMaildb.IsOpen = True Then
     Else
         oMaildb.OPENMAIL
     End If
    Set oMailDoc = oMaildb.CREATEDOCUMENT
    oMailDoc.Form = "Memo"
    oMailDoc.SENDTO = "CST_BAntoniol@xxxxxxxx.com"
    If Len(CC) = 0 Then
    Else
        oMailDoc.CopyTo = ""
    End If
    If Len(BCC) = 0 Then
    Else
        oMailDoc.blindCopyTo = ""
    End If
    oMailDoc.Subject = "Test"
    oMailDoc.Body = "Essai de message"
    oMailDoc.SAVEMESSAGEONSEND = SaveIt
    DoEvents
    lblStatus.Caption = "Looking for attached files..."
    Call Sleep(1000)

    If Attachment <> vbNullString Then
        Set oAttachME = oMailDoc.CREATERICHTEXTITEM(STR_ATTACHMENT)
        Set oEmbedObj = oAttachME.EMBEDOBJECT(1454, _
                vbNullString, Attachment, STR_ATTACHMENT)
        oMailDoc.CREATERICHTEXTITEM _
                (STR_ATTACHMENT)
    End If
    DoEvents
    oMailDoc.PostedDate = Now()
    

 'To send the message, remove the quotes characters (') near each line
   lblStatus.Caption = "Sending message..."
   Call Sleep(1000)
  '
   oMailDoc.SEND 0, RECIPIENT
   lblStatus.Caption = "Message sent"

   MsgBox "Your message has been sent successfully...", 64, "End"


L_ExCannotCreateNotesSession:
    Set oMaildb = Nothing
    Set oMailDoc = Nothing
    Set oAttachME = Nothing
    Set oSession = Nothing
    Set oEmbedObj = Nothing
    Exit Sub
L_ErrCannotCreateNotesSession:
  Select Case Err
      Case 429
          MsgBox "Impossible de localiser un Client Notes; " & _
                     "Votre message n'a pas été envoyé !", 16, _
                          "Lotus Notes requis"
      Case Else
        MsgBox "Un erreur a empêché l'envoi du message." & _
                  vbCrLf & "Veuillez en référer à votre administrateur " & _
                      "pour lui soumettre cette erreur..." & vbCrLf & Error, 16, "Error #" & str(Err)
  End Select
  Resume L_ExCannotCreateNotesSession
End Sub

Cependant la procédure d'envoi de message ne se lance pas

Avec Débug puis F8, je n'arrive pas a sortir de la procédure du "bouton_Click()". Un message d'erreur apparait:
"Couldn t find the specific Object"



Je suis dessus depuis ce matin et étant débutant je n'arrive pas à m'en sortir.

auriez vous quelques conseils pour m'aider à résoudre ce problème?

Merci d'avance.

Bruno
 

brunounours

XLDnaute Nouveau
Re : Adaptation code pour envoi d'un message avec Lotus Note 6.5

Voici mon code final qui je pense adapté correctement pourra servir à d'autres personnes.
Code:
'---------- API -----------
'pour faire passer au premier plan
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
'pour ouvrir la fenêtre
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, _
                    ByVal nCmdShow As Long) As Long
'pour vérifier si Lotus est ouvert
Private Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
     
Dim sSrvr As String 'Le serveur de mail de l'utilisateur courant
Dim MailDbName As String 'Le nom de la base mail de l'utilisateur courant
Dim UserName As String 'Le nom de l'utilisateur courant

Dim retVal As Variant 'La valeur de retour de la fonction

'---------------- fonction ouverture de session Notes -----------
Function CreateNotesSession() As Boolean
    Const notesclass$ = "NOTES"
    Const SW_SHOWMAXIMIZED = 3 'plein ecran
  Const SW_SHOWMMINIZED = 2 'reduire
  Const SW_SHOWWINDOW = 1 'fenetre
  Const SW_SHOW = 5
     
    Dim Lotus_Session As Object
    Dim rc&
    Dim lotusWindow&
     
'    lotusWindow = FindWindow(notesclass, vbNullString)

'    sSrvr = Lotus_Session.GETENVIRONMENTSTRING("MailServer", True)
'    MailDbName = Lotus_Session.GETENVIRONMENTSTRING("MailFile", True)
'    UserName = Lotus_Session.UserName
   
'    DoEvents
  'Ouverture de Lotus Notes
  'Mettre votre chemin d'accès pour notes.exe et notes.ini'
   'retVal = Shell("C:\Program Files\lotus\notes\notes.exe =C:\Program Files\lotus\notes\notes.ini", vbMaximizedFocus)

    'verifier que Lotus est bien ouvert (recupere le handle)
  lotusWindow = FindWindow(notesclass, vbNullString)
    If lotusWindow <> 0 Then
        rc = ShowWindow(lotusWindow, SW_SHOW)
        rc = SetForegroundWindow(lotusWindow)
        CreateNotesSession = True
    Else
         CreateNotesSession = False
    End If
End Function






Private Sub CommandButton1_Click()

 Const EMBED_ATTACHMENT As Integer = 1454
    Const EMBED_OBJECT As Integer = 1453
    Const EMBED_OBJECTLINK As Integer = 1452
      
    Dim s As Object ' use back end classes to obtain mail database name
  Dim db As Object '
  Dim doc As Object ' front end document
  Dim beDoc As Object ' back end document
  Dim workspace As Object ' use front end classes to display to user
  Dim bodypart As Object '
  Dim bodyAtt As Object '
  Dim lbsession As Boolean
      
    lbsession = CreateNotesSession
      
    If lbsession Then
        'cree la session Lotus Notes
      Set s = CreateObject("Notes.Notessession")
        'se connecte a sa database
      Set db = s.getDatabase(sSrvr, MailDbName)
        If db.IsOpen = True Then
            'database deja ouvert
      Else
            Call db.Openmail
        End If
        'cree un document memo
      Set beDoc = db.CreateDocument
        beDoc.Form = "Memo"
         
         'construction du mail
      Set bodypart = beDoc.CreateRichTextItem("Body")
        'beDoc.From = "Moi" 'inutile
      beDoc.SendTo = UserFormEMail.TextBox9.Value
        beDoc.CopyTo = CCToAdr
        beDoc.BlindCopyTo = BCCToAdr
        beDoc.Subject = UserFormEMail.TextBox10.Value & " Pendiente"
        
       
With bodypart
.AppendText "Buenos Dias,"
.AddNewline 2
.AppendText "Usted podrìa enviarme el Order Entry Form del (de los) proyecto(s) sigienete(s):"
.AddNewline 2
For i = 0 To UserFormEMail.ListBox2.ListCount - 1
.AppendText UserFormEMail.ListBox2.List(i) & " --- " & UserFormEMail.ListBox3.List(i)
.AddNewline 2
Next i
.AddNewline 2
.AppendText "Un saludo Cordial"
.AddNewline 1
.AppendText "Bruno Antoniol"
.AddNewline 3
End With

        '-----------------------------------------
      'Remarque s'il y a des destinataires multiples, il suffit de mettre un tableau
      'd'e-mail dans SendTo (CopyTo,BlindCopyTo)
      'exemple :
      'Dim recip(25) as variant
      'recip(0) = "emailaddress1"
      'recip(1) = "emailaddress2" e.t.c
      'beDoc.sendto = recip
      '----------------------------------------
      ' documents joint 1
      If Len(Attach1) > 0 Then
            If Len(dir(Attach1)) > 0 Then
               Set bodyAtt = bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach1, dir(Attach1))
            End If
        End If
      
        ' documents joint 2
      If Len(Attach2) > 0 Then
            If Len(dir(Attach2)) > 0 Then
                Call bodyAtt.EmbedObject(EMBED_ATTACHMENT, "", Attach2, dir(Attach2))
            End If
        End If
             
 For i = 0 To UserFormEMail.ListBox2.ListCount - 1
Textei = Textei & ListBox2.List(i) & " --- " & ListBox3.List(i) & Chr(10) & Chr(10)
Next i

        'Affichage du mail dans Lotus Notes
      Set workspace = CreateObject("Notes.NotesUIWorkspace")
        Call workspace.EditDocument(True, beDoc).FieldSetText("Body", "Bonjour Monsieur " & TextBox1 & " " & ComboBox1 & "," & Chr(10) & Chr(10) & _
"Je vous écrit concernant les projets: " & Listei & Chr(10) & Chr(10) & _
"Afin que vous apportiez les précisions suivantes: " & CheckBox1.Caption & _
" avant la date suivante: " & TextBox2 & Chr(10) & Chr(10) & Chr(10) & " Meilleures Salutations.Bruno")            


      
        Set s = Nothing
        Else
            MsgBox "Votre Lotus Notes est fermé !"
    End If


End Sub

Cdt et bonne chance si vous utilisez Lotus notes!! :mrgreen:

Bruno
 

Discussions similaires

Statistiques des forums

Discussions
312 488
Messages
2 088 859
Membres
103 978
dernier inscrit
bderradji