Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Word Doc As Email Body

987 views
Skip to first unread message

TJ

unread,
May 27, 2003, 6:42:55 PM5/27/03
to
I apologize if this question has already been answered.
I've searched the posts but didn't find anything. I'm
using Outlook 98, Word 2000, and Access 2000. I need to
generate a new email message from an Access form, insert a
Word document as the email body, and attach additional
files as attachments. I can generate the base email from
Access and attach the 'additional files' as attachments
using:

.Attachments.Add "file path here",olByValue

I have not been able to find a way to attach the Word
document as the email body however. There must be a way to
do this since I can create the base email manually by
using Insert/File/As Text and then selecting the Word
document. I hope someone can help.

Harold W Wood

unread,
May 27, 2003, 7:43:30 PM5/27/03
to
item.body = activedocument.selection.wholestory

"TJ" <jke...@mccnh.com> wrote in message
news:349401c324a1$5082cd70$a001...@phx.gbl...

Sue Mosher [MVP]

unread,
May 27, 2003, 10:22:51 PM5/27/03
to
Note, though, that this may force the message format to RTF and will not preserve any formatting. To preserve formatting, one idea would be to save the Word doc as an HTML File, then get the text of that file, and set Item.HTMLBody.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm


"Harold W Wood" <woody...@pacific.net.id> wrote in message news:ehFhIoKJ...@TK2MSFTNGP11.phx.gbl...

TJ

unread,
Jun 1, 2003, 12:00:24 PM6/1/03
to
Sue,
After some playing I found that I needed to use
Item.Body=ActiveDocument.Selection (without
the .WholeStory, which created an error)
You are correct though that this forces the format to RTF.
I need to maintain all formatting and graphics on the
original document. You mentioned saving the document as
HTML and then using .HTMLBody but I don't know how to
referenct an HTML document. For the Word Doc I opened an
instance of Word, selected .WholeStory, then used the code
line above to insert the document into the email body. How
do I do this with an HTML document?
>.
>

Howard Kaikow

unread,
Jun 1, 2003, 4:54:49 PM6/1/03
to
In Word, WholeStory just expands the Range or Selection, you need to use
another method to get the content.
In Outlook, according to the Help in VBA, the Body property expects a
String, so you could not include formatting any graphics, other than
creating a string that encodes all the formatting and graphics.


--
http://www.standards.com/; Howard Kaikow's web site.
------------------------------------------------


"TJ" <jke...@mccnh.com> wrote in message

news:004701c32856$e953fd40$a301...@phx.gbl...

Harold Wood

unread,
Jun 4, 2003, 12:20:18 AM6/4/03
to
ok you have 2 problems realy.

first how to programatically save a word document in HTML format. This
should solve that problem.
-----------------------------------------------------------

Sub Save_Document(strPath As String, StrSep As String, StrName As
String)
Dim strWrk As String

Options.DefaultFilePath(wdDocumentsPath) = strPath

strWrk = "HTML Format Doc " & Trim(strName) & ".HTM"

ActiveDocument.SaveAs FileName:=strWrk, _
FileFormat:=wdFormatHTML, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="",
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData _
:=False, SaveAsAOCELetter:=False

End Sub

-----------------------------------------------------------
next problem is reading that into the body of an email message

-----------------------------------------------------------
Sub Create_Response(strWhoTo as string strName As String, Strletter As
String, intMenu as integer)

dim objtext as object
dim vartext as object
dim inptext as object

dim outItem as outlook.MailItem

Dim strSubject As String
Dim strBody As String

On Error Resume Next

Set objText = CreateObject("Scripting.FileSystemObject")
If Err <> 0 Then
'system error unable to create file system object
Beep
MsgBox "unable to create File System Object: " & Str(Err) _
& Chr(13) & Chr(10) _
& Err.Source _
& Chr(13) & Chr(10) _
& Err.Description, vbCritical, "SYSTEM ERROR"
UserForm_Terminate
Exit Sub
End If

Set varText = objText.getfile("C:\My Documents\LetterTexts\" & strName)
If Err <> 0 Then
'programmer error file not found
Beep
MsgBox "Unable to Locate Letter Text File: " & strName _
& " For user Option: " _
& Str(intMenu), vbCritical, "SYSTEM ERROR"
Set objText = Nothing
UserForm_Terminate
Exit Sub
End If

Set inpText = varText.openastextstream(1, -2)
If Err <> 0 Then
'programmer error file not found
Beep
MsgBox "Unable to read: " & strName _
& Chr(13) & Chr(10) _
& Err.Source _
& Chr(13) & Chr(10) _
& Err.Description, vbCritical, "SYSTEM ERROR"
Set objText = Nothing
Set varText = Nothing
UserForm_Terminate
Exit Sub
Else
bolFile = True
End If

strBody = inpText.readall
inpText.Close
' set up the reply and display it

With outItem
.Reply
.to=StrWhoTo
.Subject = strSubject
'The content of the document is used as the body for the email
.BodyFormat = olFormatHTML
.HTMLBody = strBody
' you can replace the .Display with a .Send at this point
' if you but sometimes i have to customize a little to
' answer specific questions
.Display
.FlagStatus = olNoFlag
End With

End Sub

hope that this helps.

woody


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Harold W Wood

unread,
Jun 8, 2003, 7:59:51 PM6/8/03
to
dim strbody as string

strbody = activedocument.range.select = wholestory

mailitem.body = strbody

====note==== this will remove formatting, to keep formatting save the word
document as web page and then use .bodyHTML instead of .body

"TJ" <jke...@mccnh.com> wrote in message
news:349401c324a1$5082cd70$a001...@phx.gbl...

TJ

unread,
Jun 10, 2003, 3:25:32 PM6/10/03
to
Thanks, I'll give it a try.

>.
>

TJ

unread,
Jun 11, 2003, 10:40:28 AM6/11/03
to
So close...
When the message displays everything looks great but when
it is sent (and received) the graphics disappear, only a
placeholder remains. 'UserForm_Terminate' and 'Else
bolFile=True' were causing errors (variable not found) so
I have commented them out. Also, I made the
parameters 'optional' during the development phase but
that will change later. Here's the code:

Function Create_Response(Optional strWhoTo As String,
Optional strName As String, Optional strSubject As String)
As Boolean
'strWhoTo is the email address, strName is the document
name, strSubject is the email subject line text

'**********************************************************
******
'* This code provided by Harold Wood
<woody...@pacific.net.id>
'* 6/10/2003 12:25:32 PM
'**********************************************************
******

Dim objText As Object 'variable to hold
Scripting.FileSystemObject
Dim varText As Object 'variable to hold the cover letter
document
Dim inpText As Object 'variable to hold the cover letter
document text

Dim myOutlookApp As Outlook.Application 'create a
reference to Outlook object
Dim newMessage As Outlook.mailItem 'create a reference to
a new email object
Dim strBody As String 'variable to hold the email body text
Dim newAtt As Outlook.Attachment 'create a reference to an
attachment object

Set myOutlookApp = New Outlook.Application
Set newMessage = myOutlookApp.CreateItem(olMailItem)


On Error Resume Next


Set objText = CreateObject("Scripting.FileSystemObject")
If Err <> 0 Then
'system error unable to create file system object
Beep
MsgBox "unable to create File System Object: " & Str
(Err) _
& Chr(13) & Chr(10) _
& Err.Source _
& Chr(13) & Chr(10) _
& Err.Description, vbCritical, "SYSTEM ERROR"
'UserForm_Terminate

Exit Function
End If


' Check if letter exists
Set varText = objText.getfile("H:\DTITrainPackageMay03\DTI
Email\e-mail cover letter 052803.htm")
If Err <> 0 Then


'programmer error file not found
Beep
MsgBox "Unable to Locate Letter Text File:" & strName _
& " For user Option: " _

& vbCritical, "SYSTEM ERROR"


Set objText = Nothing
'UserForm_Terminate

Exit Function
End If

' Open the letter as read only


Set inpText = varText.openastextstream(1, -2)
If Err <> 0 Then
'programmer error file not found
Beep
MsgBox "Unable to read: " & strName _
& Chr(13) & Chr(10) _
& Err.Source _
& Chr(13) & Chr(10) _
& Err.Description, vbCritical, "SYSTEM ERROR"
Set objText = Nothing
Set varText = Nothing
'UserForm_Terminate

Exit Function
'Else


'bolFile = True
End If

strBody = inpText.readall
inpText.Close

' set up the reply and display it

With newMessage

.Reply
.To = "jke...@mccnh.com " 'strWhoTo


.Subject = "strSubject"
'The content of the document is used as the body for
the email
'.BodyFormat = olFormatHTML
.HTMLBody = strBody

' you can replace the .Display with a .Send at this point

' if you want but sometimes i have to customize a little to


' answer specific questions
.Display
.FlagStatus = olNoFlag
End With

End Function

>.
>

Harold Wood

unread,
Jun 11, 2003, 7:21:50 PM6/11/03
to
The method that i use works great on keeping formatting but it doesnt
work for graphics, you might try altering the save picture option when
you create the webpage.
0 new messages