Martin_62
03-15-2023, 08:55 AM
Hi folks,
I'm using VBA in OUTLOOK for the first time(till now only used it in EXCEL) ....
I have the following code :
Sub ScreenAndSend()
Dim olAPP As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olFolder As Outlook.Folder
Dim olMailOutput As Outlook.MailItem
Dim StartTime as Single
Dim ExtTime as single
fLoop As Boolean
ExtTime = 100
fLoop = true
While fLoop
'somewhere in my code :
Set olMailOutput = Application.CreateItem(olMailItem)
With olMailOutput
.To = "<list of e-mail addresses"
.BCC = "<list of e-mail addresses"
.Subject = "my subject"
.BodyFormat = olFormatHTML
.Body = "content of the mail"
.Send
Debug.Print "mail send"
End with
StartTime = Timer
Do While Timer < StartTime + ExtTime
DoEvents ' Yield to other processes.
Loop
Debug.Print "LOOPED"
Wend
End sub
Everything works fine, including the 'message send' notification.
But the mail isn't send (that is, they're not arriving at destination) until I stop the VBA code from executing.
Then the receivers get a mail, with a timestamp equals to the date/time when I stop the code.
The 'DoEvents'-loop (of 100 seconds) is there to free CPU for other activities.
I do get the "LOOPED" message after approx 100 seconds, confirming that I get that far.
Can anyone tell me what I'm forgetting, or doing wrong ?
Thanks,
Martin.
I'm using VBA in OUTLOOK for the first time(till now only used it in EXCEL) ....
I have the following code :
Sub ScreenAndSend()
Dim olAPP As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olFolder As Outlook.Folder
Dim olMailOutput As Outlook.MailItem
Dim StartTime as Single
Dim ExtTime as single
fLoop As Boolean
ExtTime = 100
fLoop = true
While fLoop
'somewhere in my code :
Set olMailOutput = Application.CreateItem(olMailItem)
With olMailOutput
.To = "<list of e-mail addresses"
.BCC = "<list of e-mail addresses"
.Subject = "my subject"
.BodyFormat = olFormatHTML
.Body = "content of the mail"
.Send
Debug.Print "mail send"
End with
StartTime = Timer
Do While Timer < StartTime + ExtTime
DoEvents ' Yield to other processes.
Loop
Debug.Print "LOOPED"
Wend
End sub
Everything works fine, including the 'message send' notification.
But the mail isn't send (that is, they're not arriving at destination) until I stop the VBA code from executing.
Then the receivers get a mail, with a timestamp equals to the date/time when I stop the code.
The 'DoEvents'-loop (of 100 seconds) is there to free CPU for other activities.
I do get the "LOOPED" message after approx 100 seconds, confirming that I get that far.
Can anyone tell me what I'm forgetting, or doing wrong ?
Thanks,
Martin.