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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| 'vbfrance
Option Explicit
'---------- API -----------
'pour faire passer au premier plan
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
'pour ouvrir la fenetre
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
'pour verifier si la 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 'the mail server for the current user
Dim MailDbName As String 'THe current users notes mail database name
Dim UserName As String 'The current users notes name
Dim retval As Variant 'Holds return value for functions handle
'---------------- fonction ouverture de session Notes -----------
Function CreateNotesSession() As Object
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&
On Error GoTo errorhandler
lotusWindow = FindWindow(notesclass, vbNullString)
'If lotusWindow <> 0 Then
Set Lotus_Session = CreateObject("Notes.NotesSession")
'Else
'Set Lotus_Session = GetObject(, "Notes.NotesSession")
'End If
sSrvr = Lotus_Session.GETENVIRONMENTSTRING("MailServer", True)
MailDbName = Lotus_Session.GETENVIRONMENTSTRING("MailFile", True)
UserName = Lotus_Session.UserName
DoEvents
'Ouverture de Lotus Notes
'retval = Shell("C:\APPLI\Notes5\notes.exe =h:\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)
Set CreateNotesSession = Lotus_Session
Else
Set CreateNotesSession = Nothing
End If
Exit Function
errorhandler:
If Err = 429 Then
'Il suffit de lancer le fichier "notesw32.reg" présent dans le repertoire Notes de Lotus!!!!
Dim pret
pret = MsgBox("Vous devez lancer LOTUS NOTES AVANT" & vbCr & "cliquez quand vous êtes pret.", vbOKCancel)
If pret = vbOK Then
Resume
Else: End
End If
Else
MsgBox Err & vbCr & Err.Description
End If
End Function
Sub CreateMailandAttachFileAdr(Optional IsSubject As String = "", Optional SendToAdr As String, Optional CCToAdr As String, Optional BCCToAdr As String = "", Optional Attach1 As String = "", Optional Attach2 As String = "", Optional body As String = "")
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 Object
Set lbsession = CreateNotesSession
If Not lbsession Is Nothing Then
'cree la session Lotus Notes
'Set s = CreateObject("Notes.NotesSession")
'se connecte a sa database
On Error Resume Next
Set db = lbsession.getDatabase(sSrvr, MailDbName)
If Err = 8965 Then
Dim rc
rc = SetForegroundWindow(FindWindow("NOTES", vbNullString))
MsgBox "Cliquez pour continuer"
Set db = lbsession.getDatabase(sSrvr, MailDbName)
Err.Clear
End If
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 = SendToAdr
beDoc.CopyTo = CCToAdr
beDoc.BlindCopyTo = BCCToAdr
beDoc.Subject = IsSubject
'-----------------------------------------
'Remarque si destinataire multiple il suffie 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
'Affichage du mail dans Lotus Notes
Set workspace = CreateObject("Notes.NotesUIWorkspace")
Dim c As Object
Call workspace.EditDocument(True, beDoc).FieldSetText("Body", body)
Set s = Nothing
Else
MsgBox "Votre Lotus Notes est fermé !"
End If
End Sub |
Partager