Check createobject completed before send email

Peter.Stevens2

Board Regular
Joined
Sep 16, 2008
Messages
56
Hi <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I am using a macro to send several emails from outlook 2000.<o:p></o:p>
<o:p></o:p>
The problem is that whilst sending the emails most of the time the sendkeys work but other times the windows remain open in the background. I am guessing its a timing issue : by this I mean that when the first email is sent it has not quite finished before then next one tries to send. I have tried varying the waittime before sends but seems temperamental. <o:p></o:p>
<o:p></o:p>
Question: Is there a way to check createobject has completed its spawn process before continuing ?. <o:p></o:p>
<o:p></o:p>
It would be great to use .recipients.add but this has the effect if getting that annoying Outlook Security Warning message that asks the user to tick Allow external macro intrusions and send then press send - which is undesirable.<o:p></o:p>
<o:p></o:p>
Question : Is there a way of placing two email addresses in the .To field i.e. .To = (testemail1@rolls-royce.com; testemail2@rolls-royce.com)<o:p></o:p>
If so I would not need to send twice.<o:p></o:p>

Code:
    Set myOlApp = CreateObject("Outlook.Application")   
    Set myMail = myOlApp.CreateItem(olMailItem)         
    
    If Application.Wait(Now + TimeValue("0:00:01")) Then
        With myMail
            .Display
            .To = email_recipient_1
            .Subject = "Test 1"
            .Body = mailBody        
        End With
        SendKeys ("^~")            
    End If
      
    Set myOlApp = CreateObject("Outlook.Application")   'Create outlook
    Set myMail = myOlApp.CreateItem(olMailItem)         'create mail item
    If Application.Wait(Now + TimeValue("0:00:02")) Then
        With myMail
            .Display
            .To = email_recipient_2
            .Subject = "test"
            .Body = mailBody                                            
        End With
        SendKeys ("^~")            
    End If
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You can use this;

Code:
Sub Test()
    email_recipient_1 = "testemail1@rolls-royce.com"
    email_recipient_2 = "testemail2@rolls-royce.com"
    Set myOlApp = CreateObject("Outlook.Application")
    Set myMail = myOlApp.CreateItem(0)
    With myMail
        .To = email_recipient_1
        .cc = email_recipient_2
        .Subject = "Test 1"
        .Body = "Test message"
        .Send
    End With
End Sub

Or, this...

Code:
Sub Test2()
    email_recipient_1 = "testemail1@rolls-royce.com"
    email_recipient_2 = "testemail2@rolls-royce.com"
    Set myOlApp = CreateObject("Outlook.Application")
    Set myMail = myOlApp.CreateItem(0)
    With myMail
        .To = email_recipient_1 & ";" & email_recipient_2
        .Subject = "Test 1"
        .Body = "Test message"
        .Send
    End With
End Sub
 
Upvote 0
Thanks for the reply but placing two emails i.e.

.To = email_recipient & ";" & email_recipient_cc
does not work as I have check in debug.

As per above placing a .CC or .Re4cipient.Add makes an unwanted Outlook Security window pop up.

Any further help would be welcome ... :confused:
 
Upvote 0

Forum statistics

Threads
1,215,573
Messages
6,125,608
Members
449,238
Latest member
wcbyers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top