Triggering Outlook's Send\Receive button 
Author Message
 Triggering Outlook's Send\Receive button

You're right, there doesn't seem to be any way to do this through the object
model.  One of many glaring omissions.  Try this:

Public Function DoSendReceive() As Boolean

    Dim objCBarButton As CommandBarButton

    Set objCBarButton =
Application.ActiveExplorer.CommandBars.FindControl(ID:=5488)

    If objCBarButton Is Nothing Then
        DoSendReceive = False
    Else
        objCBarButton.Execute
        DoSendReceive = True
    End If
End Function

The function will return True if successful and False otherwise.  It's a bit
ugly, but it should work and it's the only way I can see of doing it.  For
extra robustness, you should add some code which creates an invisible button
with an ID of 5488 if one doesn't exist and deletes it again afterward.

James


Quote:
> Does anyone know how to trigger Outlook's Send/Receive button
> from within a VB application?

> I already have a working program that starts up an instance of Outlook
> and creates various e-mail messages. However the [mailitem].Send
> method merely puts the messages into the outbox. What I want to do
> before quitting is make Outlook go on-line and actually send this
> batch of messages, just as if I had clicked the Send/Receive button or
> pressed the <F5> key.

> I'm sure there's an easy way to do it but I can't find it in the Office
> helpfile and Outlook still has no macro recorder.

> Hopefully,

> Christy



Mon, 28 Jul 2003 20:37:59 GMT  
 Triggering Outlook's Send\Receive button
I have several programs running that send email every hour or so using
Outlook. The code below works like a champ. It will start a new
instance of Outlook, create the new email and send it. Works ever time.
But it may not send the email till the instance of Outlook closes.
Hope this helps...

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
  With objOutlookMsg
    .To = cmbSendTo.Text
    .Subject = "Hstorian Status"
    .Body = "Put text here."
    .Importance = olImportanceHigh
    .Send
  End With
 Set objOutlookMsg = Nothing
 ' Close Outlook instance: Important!
 Set objOutlook = Nothing



Quote:
> Does anyone know how to trigger Outlook's Send/Receive button
> from within a VB application?

> I already have a working program that starts up an instance of Outlook
> and creates various e-mail messages. However the [mailitem].Send
> method merely puts the messages into the outbox. What I want to do
> before quitting is make Outlook go on-line and actually send this
> batch of messages, just as if I had clicked the Send/Receive button or
> pressed the <F5> key.

> I'm sure there's an easy way to do it but I can't find it in the
Office
> helpfile and Outlook still has no macro recorder.

> Hopefully,

> Christy

Sent via Deja.com
http://www.deja.com/


Mon, 28 Jul 2003 22:23:14 GMT  
 Triggering Outlook's Send\Receive button
There are a few potential pitfalls with this code.  The first is that you
don't say how you're creating your Outlook instance.  In my experience,
Outlook will often prompt for the profile to be used when started through
Automation.  This is the case even if you set it to open a profile by
default.  To make this 'reliable', I have found it necessary to start
Outlook with a command line.

The second problem is that with this type of automation, you cannot
guarantee that simply setting a variable referencing the Outlook instance to
nothing will close Outlook.  A safer approach is to explicitly close the
session using objOutlook.Quit.

Of course, if you have to close Outlook just to send a message, it's going
to be very time consuming!

Quote:

> I have several programs running that send email every hour or so using
> Outlook. The code below works like a champ. It will start a new
> instance of Outlook, create the new email and send it. Works ever time.
> But it may not send the email till the instance of Outlook closes.
> Hope this helps...

> Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
>   With objOutlookMsg
>     .To = cmbSendTo.Text
>     .Subject = "Hstorian Status"
>     .Body = "Put text here."
>     .Importance = olImportanceHigh
>     .Send
>   End With
>  Set objOutlookMsg = Nothing
>  ' Close Outlook instance: Important!
>  Set objOutlook = Nothing



> > Does anyone know how to trigger Outlook's Send/Receive button
> > from within a VB application?

> > I already have a working program that starts up an instance of Outlook
> > and creates various e-mail messages. However the [mailitem].Send
> > method merely puts the messages into the outbox. What I want to do
> > before quitting is make Outlook go on-line and actually send this
> > batch of messages, just as if I had clicked the Send/Receive button or
> > pressed the <F5> key.

> > I'm sure there's an easy way to do it but I can't find it in the
> Office
> > helpfile and Outlook still has no macro recorder.

> > Hopefully,

> > Christy

> Sent via Deja.com
> http://www.deja.com/



Tue, 29 Jul 2003 00:50:44 GMT  
 Triggering Outlook's Send\Receive button


Quote:
> You're right, there doesn't seem to be any way to do this through the
object
> model.  One of many glaring omissions.  Try this:

> Public Function DoSendReceive() As Boolean

>     Dim objCBarButton As CommandBarButton

>     Set objCBarButton =
> Application.ActiveExplorer.CommandBars.FindControl(ID:=5488)

>     If objCBarButton Is Nothing Then
>         DoSendReceive = False
>     Else
>         objCBarButton.Execute
>         DoSendReceive = True
>     End If
> End Function

> The function will return True if successful and False otherwise.  It's a
bit
> ugly, but it should work and it's the only way I can see of doing it.  For
> extra robustness, you should add some code which creates an invisible
button
> with an ID of 5488 if one doesn't exist and deletes it again afterward.

> James

Thanks James,

That's exactly what I wanted. If anyone else is going to use it, though, I'd
better mention that you need to link the Microsoft Office object library
to your program, not just the Outlook one. This is needed for the
CommandBarButton object definition.

Regards,

Christy



Tue, 29 Jul 2003 02:02:43 GMT  
 Triggering Outlook's Send\Receive button
That's true.  I assumed the code would be run in Outlook 2000 VBA.


Quote:



> > You're right, there doesn't seem to be any way to do this through the
> object
> > model.  One of many glaring omissions.  Try this:

> > Public Function DoSendReceive() As Boolean

> >     Dim objCBarButton As CommandBarButton

> >     Set objCBarButton =
> > Application.ActiveExplorer.CommandBars.FindControl(ID:=5488)

> >     If objCBarButton Is Nothing Then
> >         DoSendReceive = False
> >     Else
> >         objCBarButton.Execute
> >         DoSendReceive = True
> >     End If
> > End Function

> > The function will return True if successful and False otherwise.  It's a
> bit
> > ugly, but it should work and it's the only way I can see of doing it.
For
> > extra robustness, you should add some code which creates an invisible
> button
> > with an ID of 5488 if one doesn't exist and deletes it again afterward.

> > James

> Thanks James,

> That's exactly what I wanted. If anyone else is going to use it, though,
I'd
> better mention that you need to link the Microsoft Office object library
> to your program, not just the Outlook one. This is needed for the
> CommandBarButton object definition.

> Regards,

> Christy



Tue, 29 Jul 2003 19:13:51 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Triggering Outlook's Send\Receive Button

2. Outlook 'send and receive'

3. Activiting the send/receive button in Outlook 2000

4. Can't send/receive in Outlook

5. outlook 2000 won't send/receive

6. Triggering Outlook's 'Send/Receive' command

7. Please Help Trigger Send & receive

8. Outlook Send Receive scribt problem

9. Outlook Send/Receive - Someone knows the answer

10. Outlook Send/Receive Group Failure

11. Outlook- Delayed sending and receiving

12. Send/Receive in Outlook - as pop server

 

 
Powered by phpBB® Forum Software