Hi Benoit,
you can use the Sample below. For the Timer add a Standardmodul (no
Classmodul) to your Project.
<DieseOutlookSitzung>
Option Explicit
Private m_lCnt As Long
Private m_lMaxCnt As Long
Private m_lInterval As Long
Public Sub Timer()
Dim sFile As String
Dim oMail As Outlook.MailItem
m_lCnt = m_lCnt + 1
If m_lCnt = m_lMaxCnt Then
modTimer.DisableTimer
End If
sFile = "c:\sounds\sounds.part" & m_lCnt & ".rar"
Set oMail = Application.CreateItem(olMailItem)
With oMail
.Recipients.Add "(e-mail address removed)"
.Subject = "Soundfile " & m_lCnt
.Attachments.Add sFile
.Send ' may raise a Securityprompt
End With
' Ability to cancel the Timer.
' Just for demonstration. While displaying this modal Dialog _
you can´t click anything in OL.
If m_lCnt < m_lMaxCnt Then
If MsgBox("Stop Timer?", vbYesNo + vbQuestion, "Timersignal " _
& m_lCnt) = vbYes Then
modTimer.DisableTimer
End If
End If
End Sub
Private Sub Application_Startup()
m_lCnt = 0
' Interval in ms (15min)
m_lInterval = 900000
' Stop Timer at MaxCnt
m_lMaxCnt = 134
If Not modTimer.EnableTimer(m_lInterval, Me) Then
MsgBox "kein Timer", vbExclamation
End If
End Sub
</DieseOutlookSitzung>
<modTimer.bas>
Option Explicit
Private Declare Function SetTimer Lib "user32.dll" (ByVal hWnd As Long,
_
ByVal nIDEvent As Long, ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32.dll" (ByVal hWnd As Long,
_
ByVal nIDEvent As Long) As Long
Const WM_TIMER = &H113 ' Timer-Ereignis trifft ein
Private hEvent As Long
Private m_oCallback As DieseOutlookSitzung
' Timer-Prozedur, welche im Abstand der festgelegten
' Millisekunden ein Ereignis sendet
Public Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long)
If uMsg = WM_TIMER Then
m_oCallback.Timer
End If
End Sub
' Startet den Timer
Public Function EnableTimer(ByVal msInterval As Long, oCallback As _
DieseOutlookSitzung) As Boolean
If hEvent <> 0 Then
Exit Function
End If
hEvent = SetTimer(0&, 0&, msInterval, AddressOf TimerProc)
Set m_oCallback = oCallback
EnableTimer = CBool(hEvent)
End Function
' Beendet den Timer
Public Function DisableTimer()
If hEvent = 0 Then
Exit Function
End If
KillTimer 0&, hEvent
hEvent = 0
Set m_oCallback = Nothing
End Function
</modTimer.bas>