PDA

View Full Version : vba script to open emails via a form



babru
04-04-2013, 07:20 AM
Hi everybody,

I'm quite new in programming vba for outlook, so I helped myself with some Excel vba code but it doesn't really work out. I am stumped. Please help me.

This is how it's supposed to work:
I have a form in which I insert the data, press ENTER and the code opens a specific email, which is already in the Code.

Here comes the catch:
The Emails are gonna be displayed and not sent (what works surprisingly)

And here is the Code: (It's a bit shortend)

Private Sub OptionButton_Absage_Click()
ComboBox1.Clear
With ComboBox1
.AddItem "Absage auf Initiativbewerbung"
.AddItem "Absage nach Erstgespräch"
.AddItem "Absage nach Zweitgespräch"
.AddItem "Absage nach Gespräch auf Messe"
.AddItem "Absage nach Anzeigenschaltung"
.AddItem "Absage an Patentanwaltskandidaten"
.AddItem "Absage auf Englisch"
End With
End Sub

Private Sub OptionButton_Eingangsbestaetigung_Click()
ComboBox1.Clear
With ComboBox1
.AddItem "Eingangsbestätigung"
.AddItem "Anforderung fehlender Unterlagen allgemein"
.AddItem "Anforderung Abiturzeugnis"
End With
End Sub

Private Sub OptionButton_sonstiges_Click()
ComboBox1.Clear
With ComboBox1
.AddItem "Anschreiben ON HOLD Kandidaten"
.AddItem "Zwischenbescheid an Bewerber"
.AddItem "Nachfassen beim Partner"
End With
End Sub

Private Sub cmd_Enter_Click()

If Me.OptionButton_Frau.Value = True Then
Call email
Unload Me
End If
End Sub

Public Sub Email_Outlook()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<FONT face=""Trebuchet MS"" size=2> " & _
"Text"

On Error Resume Next
With OutMail
.To = Me.txt_Email.Value
.CC = ""
.BCC = ""
.Subject = "Ihre Bewerbung bei Bird & Bird LLP"
.HTMLBody = strbody
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

skatonni
04-04-2013, 06:23 PM
I do not know what the question is but maybe you want to use

Call Email_Outlook rather than Call email

babru
04-11-2013, 01:04 AM
No that wasn't the question and it was a mistake I did because I shortend.

So thanks for that.

Here is the question: After filling data in the form, there should pop up an email. The user should be able to change the email and send it.

But it doesn't work. The Email is not displayed. On the other hand, ".send" instead of ".display" works.

babru
04-11-2013, 01:06 AM
This is the part which doesn't work:

If Me.OptionButton_Frau.Value = True Then
Call email_outlook
Unload Me
End If
End Sub

or this:

Public Sub Email_Outlook()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<FONT face=""Trebuchet MS"" size=2> " & _
"Text"

On Error Resume Next
With OutMail
.To = Me.txt_Email.Value
.CC = ""
.BCC = ""
.Subject = "Ihre Bewerbung bei Bird & Bird LLP"
.HTMLBody = strbody
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub