
January 18th 06, 09:01 PM
posted to microsoft.public.outlook.program_vba
|
|
Cant Send a displayed message without explorer open. Eric Legault
Thanks Eric
Still no joy .
I'll live with the outlook window left open after the code has run
Eric Legault [MVP - Outlook] wrote:
Some suggestions:
- use the MailItem.Send method rather than executing a commandbar button
- cancel the display of the e-mail if none of the recipients resolve and
force the user to send manually
- you don't need the Logon method
- trap the SyncEnd method for a defined Send/Receive group to ensure that a
forced send/receive completes before closing Outlook; use this code to force
it:
Public Sub SendReceiveNow()
Dim oCtl As Office.CommandBarControl
Dim oPop As Office.CommandBarPopup
Dim oCB As Office.CommandBar
'Use the Send/Receive on All Accounts action in the Tools
'menu to send the items from the Outbox, and receive new items
Set oCB = ActiveExplorer.CommandBars("Menu Bar")
Set oPop = oCB.Controls("Tools")
Set oPop = oPop.Controls("Send/Receive")
Set oCtl = oPop.Controls("Send/Receive All") '("All Accounts")
oCtl.Execute
Set oCtl = Nothing
Set oPop = Nothing
Set oCB = Nothing
End Sub
--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
" wrote:
Further top my last Post I'm still having problems getting the user
edited meassge to send
1. My code generates an email message which is displayed to the user
2.They edit the message add a recipient & hit send
3.It sits in the outbox italicized, not bold, and wont sent
So I wrapped the code with the following to force the sent (-Outlook
2003 with Exchange & redemption).It works but leaves an outlook
window open at the end
Set objInbox = NS.GetDefaultFolder(olFolderInbox)
Set objExplorer = objOutlook.Explorers.Add(objInbox,
olFolderDisplayNormal)
objExplorer.Display
objExplorer.WindowState = olMinimized
..
..
..Other code here
..
'Need to force the send at times outlook explorer needs to be visible
Set btn = objExplorer.CommandBars.FindControl(1, 7095)
btn.Execute
4. If I add
ObjExplorer.close
Set objexplorer = nothing
This will close outlook nicely but then the message wont sent
The next time I open outlook the message sends after a couple of
minutes.I assume by some exchange process
Questions
Is it possible to sent the email & still close down outlook
At the moment I can only sent it if an outlook window remains open
My code finishes before the user has clicked sent tho the force sent
click still seems to work
Do I open the wrong explorer window?
Many Thanks
Tony
The full code is as follows
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim NS As Object
Dim objInbox As Object
Dim objExplorer As Object
Dim objRedempMsg As Object
Dim btn As Object
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
'Logon to MAPI
Set NS = objOutlook.GetNamespace("MAPI")
NS.Logon
'this is required to get Outlook to send else it sits in the outbox
after the users hits send
'need to expose the explorer window before doing a sendkey later
Set objInbox = NS.GetDefaultFolder(olFolderInbox)
Set objExplorer = objOutlook.Explorers.Add(objInbox,
olFolderDisplayNormal)
objExplorer.Display
objExplorer.WindowState = olMinimized
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
'Create Redemption Safe Mail - library Redemption.dll
Set objRedempMsg = CreateObject("Redemption.SafeMailItem")
'Point the message to Redemption
objRedempMsg.Item = objOutlookMsg
Dim MyName As String
strTo = "
Dim strBody As String
strBody = "Attached please find a Memo which initiates a Non
Conformance". objRedempMsg
Set objOutlookRecip = .Recipients.Add(strTo )
objOutlookRecip.Type = olTo
'Send the email to DCC
' Add the CC recipient(s) the DCC .
Set objOutlookRecip = .Recipients.Add("DCC")
objOutlookRecip.Type = olCC
.Subject = "A New Non Conformance has been raised - OUTLOOK TEST
ONLY "
.Body = strBody
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objRedempMsg.Display
End If
Next
.Display
End With
'Need to force the send at times outlook explorer needs to be
visible
Set btn = objExplorer.CommandBars.FindControl(1, 7095)
btn.Execute
'objExplorer.Close
ExitProc:
Set objExplorer = Nothing
Set objOutlook = Nothing
'The word document running the code
Documents(SrcFile).Close False
Exit Sub
|