Change from an email to a word document

Pete H4H

New Member
Joined
Nov 28, 2017
Messages
4
Hi,

I have a sheet I have been working on for a while that I have pretty much got to do what I need it to do more by luck than judgement sometimes.
what I need to do now is really causing me a problem.
When I enter data via a userform it produces an email with the appropriate data on it, what I need it to do now is produce a word document that I can password protect before I send as an attachment to the email instead of having the data in the email.

It is probably easy but I just cant get it to create a word document, any help would be appreciated.
this is what i use to create the email.

Dim objOL As Object
Dim objMail As Object
Dim sEmail As String
Dim sTo As String
Dim sEmailColumn As String
Dim sSubject As String
Dim sBody As String
Dim lDataRow As Long
Dim cl As Range


Sheets("Data").Visible = True
Sheets("Data").Select
'email address
sEmailColumn = "BT"
For Each cl In Selection.Resize(, 1)
'Generate required info
lDataRow = Cells(Rows.Count, 1).End(xlUp).Row


sTo = Worksheets("Sheet1").Range("L20")
sEmail = Worksheets("Data").Range(sEmailColumn & lDataRow)
sSubject = "Request for Attendance"
sBody = "Dear " & Worksheets("Data").Range("O" & lDataRow) & _
vbNewLine & vbNewLine & "We have a new event in your area" & _
vbNewLine & "Please have a look at see who we would have available to look after this for us" & _
vbNewLine & vbNewLine & "Event Name :" & Worksheets("Data").Range("D" & lDataRow) & _
vbNewLine & "Event Date :" & Worksheets("Data").Range("F" & lDataRow) & _
vbNewLine & "Event Address :" & Worksheets("Data").Range("L" & lDataRow) & " - " & Worksheets("Data").Range("BW" & lDataRow) & _
vbNewLine & "Type of Event :" & Worksheets("Data").Range("E" & lDataRow) & _
vbNewLine & "Time :" & Worksheets("Data").Range("BR" & lDataRow) & " - " & Worksheets("Data").Range("BS" & lDataRow) & _
vbNewLine & "How Many Volunteers :" & Worksheets("Data").Range("M" & lDataRow) & _
vbNewLine & "Additional Information :" & Worksheets("Data").Range("U" & lDataRow) & _
vbNewLine & "Contact Name : " & Worksheets("Data").Range("I" & lDataRow) & _
vbNewLine & "Contact Email : " & Worksheets("Data").Range("K" & lDataRow) & _
vbNewLine & "Contact Phone Number : " & Worksheets("Data").Range("J" & lDataRow) & _
vbNewLine & vbNewLine & "Thanks" & vbNewLine & _
vbNewLine & Worksheets("Sheet1").Range("L" & 22) & _
vbNewLine & vbNewLine & Worksheets("Sheet1").Range("L" & 23) & _
vbNewLine & Worksheets("Data").Range("AI" & 5) & _
Worksheets("Sheet1").Range("K" & 12) & _
vbNewLine & Worksheets("Data").Range("AI" & 6) & Worksheets("Sheet1").Range("L" & 24) & _
vbNewLine & Worksheets("Data").Range("AI" & 7)


On Error GoTo Cleanup
'Bind to Outlook
Set objOL = CreateObject("Outlook.Application")
'Create a new email and send it
Set objMail = objOL.CreateItem(0) '0=olmailitem
With objMail
.To = sEmail
.cc = sTo
.Subject = sSubject
.Body = sBody
.Display
End With
'End If
Next cl
Cleanup:
'Release all objects
Set objMail = Nothing
Set objOL = Nothing
On Error GoTo 0
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top