Send All emails in Outbox and Quit using VBA

S

Steph_canoe

Hi,

I have MS Access creating emails objects in Outlook using a macro. I want to
send them all and close outlook after.

1-Open Outlook
2-Send all emails in the outbox folder
3-Close Outlook

How can I achieve it using VBA? Using command buttons does not seem to work
since my Outlook is in French,

I'm using Outlook 2003 SP3.

Thank You

Stephane
 
S

Sue Mosher [MVP]

You're not trying to use command button captions, are you? Use the IDs
instead, with the FindControl method. They're language-neutral. The ID for
Send All should be 5577.
 
S

Steph_canoe

Sue Mosher said:
You're not trying to use command button captions, are you? Use the IDs
instead, with the FindControl method. They're language-neutral. The ID for
Send All should be 5577.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

How would I write my code than:

Public Sub SendReceiveNowDev()

' Instantiate an Outlook Application object.
Set objOutlook = CreateObject("Outlook.Application")

'Set Btn =
Application.ActiveExplorer.CommandBars.FindControl(msoControlButton, 5577)
Btn.Execute

'Stop Outlook
objOutlook.Quit

End Sub

Seems not to work.
 
S

Steph_canoe

Here is my updated code but is not working yet:

Public Sub SendReceiveNowDev()
Dim objOutlook As Outlook.Application
Dim objCB As Office.CommandBar

On Error Resume Next

' Instantiate an Outlook Application object.
Set objOutlook = CreateObject("Outlook.Application")

'Then use the Send/Receive on All Accounts
Set objCB =
Application.ActiveExplorer.CommandBar.FindControl(msoControlButton, 5577)
objCB.Execute

Set objCB = Nothing
Set objOutlook = Nothing

'Stop Outlook
objOutlook.Quit

End Sub
 
J

Jan T.

What error do you get? If you use Create object, using late binding, you
must
make objOutlook an object. Same for objCB. Comment out your error trap
so you can watch eventual error code or description to see what is going
wrong.

You probably still have to check you buttonID because i don't know what is
the
right code her.

Try someting like this:

Public Sub SendReceiveNowDev()
Dim objOutlook As Object 'Outlook.Application
Dim objCB As Object 'Office.CommandBar

' On Error Resume Next

' Instantiate an Outlook Application object.
Set objOutlook = CreateObject("Outlook.Application")

'Then use the Send/Receive on All Accounts
Set objCB = _
objOutlook.ActiveExplorer.CommandBar.FindControl(msoControlButton, 5577)
objCB.Execute

Set objCB = Nothing
Set objOutlook = Nothing

'Stop Outlook
objOutlook.Quit

End Sub

Best wishes
Jan T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top