dmkennard2
Technical User
Hi,
I have the following code that works and sends the required E-mail with attachment, but when i try and close Excel, Excel crashes everytime.
We are using Excel 2003 SP1. If this version is causing the problem, is there anther way of doing the same thing as we cannot upgrade to SP2 at the moment.
Private Sub cmdSendMail_Click()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
Dim address, datefrom, dateto As String
address = Right$(Range("A1"), 8)
header = Range("A1").Text
datefrom = Range("B4").Text
dateto = Range("B5").Text
ActiveWorkbook.Save
If address = "1001" Then
With OutMail
.To = "Test Email 1"
.CC = ""
.BCC = ""
.Subject = header
.Body = "Hier ist die " & header & " für die Periode vom " & datefrom & " bis " & dateto & Chr$(13) & Chr$(13) & " Viele Grüsse"
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Else
If address = "1002" Then
With OutMail
.To = "Test Email 2"
.CC = ""
.BCC = ""
.Subject = header
.Body = "Hier ist die " & header & " für die Periode vom " & datefrom & " bis " & dateto & Chr$(13) & Chr$(13) & " Viele Grüsse"
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Else
MsgBox "No such address", vbCritical, "Error"
End If
End If
Set OutMail = Nothing
Set OutApp = Nothing
frmControl.Hide
End Sub
Thanks in advance
Dazz
I have the following code that works and sends the required E-mail with attachment, but when i try and close Excel, Excel crashes everytime.
We are using Excel 2003 SP1. If this version is causing the problem, is there anther way of doing the same thing as we cannot upgrade to SP2 at the moment.
Private Sub cmdSendMail_Click()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
Dim address, datefrom, dateto As String
address = Right$(Range("A1"), 8)
header = Range("A1").Text
datefrom = Range("B4").Text
dateto = Range("B5").Text
ActiveWorkbook.Save
If address = "1001" Then
With OutMail
.To = "Test Email 1"
.CC = ""
.BCC = ""
.Subject = header
.Body = "Hier ist die " & header & " für die Periode vom " & datefrom & " bis " & dateto & Chr$(13) & Chr$(13) & " Viele Grüsse"
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Else
If address = "1002" Then
With OutMail
.To = "Test Email 2"
.CC = ""
.BCC = ""
.Subject = header
.Body = "Hier ist die " & header & " für die Periode vom " & datefrom & " bis " & dateto & Chr$(13) & Chr$(13) & " Viele Grüsse"
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Else
MsgBox "No such address", vbCritical, "Error"
End If
End If
Set OutMail = Nothing
Set OutApp = Nothing
frmControl.Hide
End Sub
Thanks in advance
Dazz