PsYiOn
06-05-2008, 10:06 AM
I have setup a small email tool as part of my VBA program, here is the code.
Sub MailTool()
' Is working in Office 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
On Error Resume Next
With OutMail
.to = "Test@test.com"
.CC = ""
.BCC = ""
.Subject = "Test Subject"
.Body = strbody
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
The email sends fine it opens outlook etc but i need to be able to set the return address to somthing different. so wehn people reply it goes to a set address or even 2 set addresses. I can do this with outlook and since vba uses outlook is there a way for me to do it in VBA?
Kind Regards
PsYiOn
Sub MailTool()
' Is working in Office 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
On Error Resume Next
With OutMail
.to = "Test@test.com"
.CC = ""
.BCC = ""
.Subject = "Test Subject"
.Body = strbody
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
The email sends fine it opens outlook etc but i need to be able to set the return address to somthing different. so wehn people reply it goes to a set address or even 2 set addresses. I can do this with outlook and since vba uses outlook is there a way for me to do it in VBA?
Kind Regards
PsYiOn