Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello!
I have made a procedure that sends Emails from Excel (2003) through the e-mail account I have set up in Outlook (2007). The procedure sends the whole workbook as an attachment. I have added the procedure, in an independent module, to two different workbooks, and its working fine. Here's the catch: In one of the workbooks, when I run the procedure it sends the e-mail immediately. In the other workbook, however, it does not send the e-mail UNTIL I open Outlook! The e-mail sending module is identical in both workbooks. Does anyone know why this happens? Is there any way to force the procedure to send the e-mail immediately without opening Outlook? I thank you in advance, Lazy Albert Check out the code: I have made a Reference to Outlook 12 in both workbooks Sub SendEmail(DireccionEmail, CuerpoEmail, SubjectEmail) Dim bOutlookStarted As Boolean Dim bTerminateMerge As Boolean Dim intSourceRecord As Integer Dim objMailItem As Outlook.MailItem Dim objOutlook As Outlook.Application Dim strMailSubject As String Dim strMailTo As String Dim strMailBody As String Dim strOutputDocumentName As String bOutlookStarted = False Set objMerge = ActiveWorkbook ' Start Outlook as necessary On Error Resume Next Set objOutlook = GetObject(, "Outlook.Application") If Err < 0 Then Set objOutlook = CreateObject("Outlook.Application") bOutlookStarted = True End If With objMerge strMailSubject = SubjectEmail strMailBody = CuerpoEmail strOutputDocumentName = ThisWorkbook.Path & "\" & ThisWorkbook.Name strMailTo = DireccionEmail Set objMailItem = objOutlook.CreateItem(olMailItem) With objMailItem .Subject = strMailSubject .Body = strMailBody .To = strMailTo .CC = " 'Me mando una copia .Attachments.Add strOutputDocumentName, olByValue, 1 .Send End With Set objMailItem = Nothing End With MsgBox "E-mail enviado con éxito." End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Bizarre XLA behaviour | Excel Discussion (Misc queries) | |||
Tricky Tricky episode 2!!! | Excel Programming | |||
Tricky Tricky episode 2!!! | Excel Programming | |||
Bizarre macro problem | Excel Programming | |||
Bizarre and frustrating bug | Excel Programming |