Cant Send a displayed message without explorer open. Eric Legault & et al

T

tcmill

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 = "(e-mail address removed)"


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
 
G

Guest

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
 
T

tcmill

Thanks Eric
Still no joy .
I'll live with the outlook window left open after the code has run
 
G

Guest

If you're code is essentially calling Outlook to send a message and close it
down from an external application (not an Outlook COM Add-In or a VBA macro),
then here's some "best practice" code that loads Outlook if necessary, or
retrieves a handle to Outlook if it is already open. Outlook's state is
important in regards to setting Explorer objects - you only need to create
them if Outlook is closed. If you do create them, you have to make sure to
close and destroy all objects so that Outlook can shut down properly:

Dim objOL As Outlook.Application, blnNewOutlook As Boolean
Dim objExp As Outlook.Explorer
Dim objNS As Outlook.NameSpace
Dim objMail As Outlook.MailItem

'Retrieve an existing Outlook Application object if it is already loaded
Set objOL = GetObject(, "Outlook.Application")
If objOL Is Nothing Then
'Outlook is closed; open it
Set objOL = New Outlook.Application
blnNewOutlook = True
End If
Set objNS = objOL.GetNamespace("MAPI")

If blnNewOutlook = True Then
Set objExp =
objOL.Explorers.Add(objNS.GetDefaultFolder(olFolderInbox),
olFolderDisplayNormal)
objExp.Activate 'Show Outlook
Else
' Set objExp = objOL.ActiveExplorer
End If

Set objMail = objOL.CreateItem(olMailItem)
objMail.Subject = "test"
objMail.To = "(e-mail address removed)"
objMail.Send

Set objMail = Nothing

If blnNewOutlook = True Then
objExp.Close
objOL.Quit
End If

Set objExp = Nothing
Set objNS = Nothing
Set objOL = Nothing
 
M

Michael Bauer

Am 17 Jan 2006 12:22:49 -0800 schrieb (e-mail address removed):

Tony, you could wait until your sent message arrives in the SentItems folder
(use the ItemAdd event). If that happened you could close OL.
 

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