Do until mail.sent not working
The classic "do until" loop!
The do until
loop in VBA is used to execute a block of code repeatedly until a specified condition is met. In your case, you're trying to use it to send an email until the Mail.Send
method returns True
.
The issue you're facing is likely due to the fact that the Mail.Send
method returns a Boolean
value indicating whether the email was sent successfully or not. However, the do until
loop is expecting a Boolean
value to evaluate as a condition, which is not the case here.
To fix this, you can use a workaround by creating a variable to store the result of the Mail.Send
method and then use that variable as the condition for the do until
loop. Here's an example:
Dim sent As Boolean
Do Until sent
On Error Resume Next
Mail.Send
sent = Mail.Send = True
Loop
In this example, we declare a sent
variable and initialize it to False
. Then, we use the do until
loop to execute the code inside the loop until the sent
variable is True
.
Inside the loop, we use the On Error Resume Next
statement to ignore any errors that might occur during the email sending process. Then, we call the Mail.Send
method and store the result in the sent
variable. Finally, we set the sent
variable to True
if the email was sent successfully (i.e., Mail.Send = True
).
By using this workaround, you should be able to achieve the desired behavior of sending an email until it's successfully sent.