PDA

View Full Version : Email Word file



johnjgsmith
02-01-2007, 11:25 AM
Hi

I found this excellent tutorial on sending emails from Word:
w ww . vbaexpres . com / kb / getarticle. p h p ? kb_id = 310 (sorry for those spaces, but cos this is my first post, i can't use links)


But I've 1 "problem".

When I've reviewed reports here at work regarding our borrowers, I email them to another department for actioning. Every email subject contains the name and account number of the borrower. This information is on the first line of the report.

Is there a way to have a "dynamic" email subject, copied from the first line of the report, and not one that's hard coded in the vba code (as in Steiner's code)?

One email will have "19930098 - Smith" as subject, another "788883772 - Johnson".

Is this possible?

Many thanks for your help.

John

lucas
02-01-2007, 11:44 AM
This might help:
Sub FirstLineIsSubject()
'first line is the subject line, includes all text in the body
Dim AppOutlook As Object
Set AppOutlook = CreateObject("Outlook.application")
With AppOutlook.CreateItem(olMailItem)
.To = "Anyone@home.com"
.Subject = ActiveDocument.Sentences(1).Text
.Body = ActiveDocument.Content
' .Send
.Display
End With
Set AppOutlook = Nothing
End Sub


You could combine it with this which puts the first line as the email address to do both:
Sub FirstLineIsAddress()
'first line is the email address-second line is subject line, includes all text in the body
Dim AppOutlook As Object
Set AppOutlook = CreateObject("Outlook.application")
With AppOutlook.CreateItem(olMailItem)
.To = ActiveDocument.Sentences(1).Text
.Subject = ActiveDocument.Sentences(2).Text
.Body = ActiveDocument.Content
' .Send
.Display
End With
Set AppOutlook = Nothing
End Sub

lucas
02-02-2007, 10:29 AM
Hi John,
I just took a minute to look at Steiners code and I see it's not for outlook. Look for this sub at the bottom of his code and change it as I have here and it works for me to put the first line in as the subject of the email:
Sub eMailActiveDocument()
Dim Doc As Document

Application.ScreenUpdating = False
Set Doc = ActiveDocument
Doc.Save

SendIt "me@here.com", ActiveDocument.Sentences(1).Text, "Hi, read this:", Doc.FullName

Application.ScreenUpdating = True
Set Doc = Nothing
End Sub