PDA

View Full Version : send email with body from textboxes on user form



saban
04-05-2006, 08:18 AM
I would like to send an email using form with text boxes on it
User fills in textboxes and when he press button send the mail is send

I would like from macro ;
When user fills in all the textboxes the msgbox should appear with buttons vbYesNo and if user chooses Yes then procedure should be repeated but no to send another mail just add the next textboxes that were filled into e-mail's body

thnx
saban

geekgirlau
04-05-2006, 10:58 PM
Can you post a sample containing your form, the information you want to appear on the email, and confirm whether you want to send using Outlook.

saban
04-06-2006, 01:07 AM
Why is when I try to put content(with table) of active document which contains table to body of e-mail, the table is not inserted

Private Sub CommandButton1_Click()
Selection.TypeText ("Zahtevek za aliniranje") & vbCrLf & vbCrLf
Selection.TypeText UserForm2.TextBox1 & vbTab
Selection.TypeText UserForm2.TextBox2 & vbTab
Selection.TypeText UserForm2.TextBox3 & vbTab
Selection.TypeText UserForm2.TextBox4 & vbTab & vbCrLf
UserForm2.TextBox1 = ""
UserForm2.TextBox2 = ""
UserForm2.TextBox3 = ""
UserForm2.TextBox4 = ""
UserForm2.TextBox1.SetFocus
End Sub
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
' Dim objOutlook As Outlook.Application
'Dim objOutlookMsg As Outlook.MailItem
'Dim objOutlookRecip As Outlook.Recipient
'Dim objOutlookAttach As Outlook.Attachment
Dim s As Range

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("lpoljak@europarl.eu.int")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("")
'objOutlookRecip.Type = olCC
' Add the BCC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("")
'objOutlookRecip.Type = olBCC
Documents.Add
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
Set s = ActiveDocument.Content
ActiveDocument.Content.Copy
's = Selection
' Set the Subject, Body, and Importance of the message.
.To = "lppoljak@lu.coditel.net"
.Subject = "Aliniranje"
.Body = s
.Importance = olImportanceHigh 'High importance
.Send
' Add attachments to the message.
'If Not IsMissing(AttachmentPath) Then
' Set objOutlookAttach = .Attachments.Add(AttachmentPath)
' End If
' Resolve each Recipient's name.
'For Each objOutlookRecip In .Recipients
' objOutlookRecip.Resolve
' Next
' Should we display the message before sending?

End With
Set objOutlook = Nothing
End Sub
Private Sub CommandButton5_Click()
'Dim objol As New Outlook.Application
'Dim objmail As MailItem
'Set objol = New Outlook.Application
'Set objmail = objol.CreateItem(olMailItem)
With objmail
.To = "lppoljak@lu.coditel.net"
.Subject = "Who/Me"
.Body = TextBox1.Text
.NoAging = True
'.Attachments.Add "C:\A test.xls"
.Display
End With
Set objmail = Nothing
Set objol = Nothing
SendKeys "%{s}", True

End Sub
Private Sub CommandButton2_Click()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for the new email
.To = "lpoljak@europarl.eu.int"
'Set the recipient for a copy
' .CC = "recipient2@mail.com"
'Set the subject
.Subject = "Alinirati"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With
If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
ActiveDocument.Close wdDoNotSaveChanges
UserForm2.TextBox1 = ""
UserForm2.TextBox2 = ""
UserForm2.TextBox3 = ""
UserForm2.TextBox4 = ""
UserForm2.TextBox1.SetFocus
End Sub

Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub UserForm_Initialize()
Documents.Add
UserForm2.TextBox1.SetFocus
End Sub

saban
04-06-2006, 03:52 AM
why is all formatting lost when i put activedocument contwent into body of email

fumei
04-06-2006, 10:55 PM
Is the email in plaintext?

saban
04-11-2006, 12:46 AM
Yes but why ?

geekgirlau
04-11-2006, 06:22 PM
In Outlook, have a look at Tools | Options | Mail Format - if messages are set to be composed in plain text, all formatting will be stripped. Also I'm not sure off the top of my head whether "ActiveDocument.Content" refers to the formatting as well as the text - confirmation anyone?

saban
04-12-2006, 01:44 AM
I dont think activedocument.content supports formating
I guess I should make body of e-mail in HTML format