Body mail from MsWord

G

Guest

Hi, I would like some help with creating an e-mail with macro. I have a macro
to create an e-mail, and I want that the body of the e-mail come from a .doc
file.
Any help?

By the way, here it is the simple following macro to do this:


Sub CreateMail()
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)
With objMail
.Display
.Subject = "Test"
.Importance = olImportanceHigh
.ReadReceiptRequested = True
.Sensitivity = olNormal
.Attachments.Add ("C:\Documents and Settings\Desktop\Test.txt")
.To = "(e-mail address removed)"
.Body = "Can I use MsWord?"
.Save
End With
End Sub



An easy question: how do I do to close the objMail?
objMail.Close is not working

Thanks on advance,
Marcelo
 
M

Michael Bauer

Am Tue, 27 Dec 2005 17:54:02 -0800 schrieb Marcelo:

Marcelo, you can use Word´s object model to access any document. In Outlook
add a reference to Word via Tools/References. Now you can easily explore
Word´s object model with the object browser (F2).

Reference on an opened Document: Application.Documents.Item(index)
Open a new Document: Application.Documents.Open(...)

All the Documents text is Document.Range.Text
 
G

Guest

It's a great idea, but I'm still with a doubt.

I have already the text copyed from doc Word, but when I paste it in the
mail body, I lost the format.
I'm Using:

objMail.Body = oWord.Selection.FormattedText

Why isn't it working?



"Michael Bauer" escreveu:
 
M

Michael Bauer

Am Wed, 28 Dec 2005 04:24:02 -0800 schrieb Marcelo:

Somehow I failed to notice what your real question is...

The Body property is for plain text only. I.e. there´re no formattings
possible. Use the HTMLBody property instead for html formatted text.

You could save the Document as an HTML file and then read its content (e.g.
with the Scripting.FileSystemObject).
 
G

Guest

Ok, so I did it with my code:

Set FSO = CreateObject("Scripting.FileSystemObject")
Set TS = FSO.OpenTextFile("C:\Body.html", ForReading)
strText = TS.ReadAll
With objMail
.Display
.Subject = "Test"
.To = "(e-mail address removed)"
.BodyFormat = olFormatHTML
.HTMLBody = strText
End With
....

But it get an error with
Set TS = FSO.OpenTextFile("C:\Body.html", ForReading)

Am I doing somenthing wrong?



"Michael Bauer" escreveu:
 
P

papou

Hello Marcelo
Not too sure but you may check:
Replace the argument ForReading with value 1 ie:
Set TS = FSO.OpenTextFile("C:\Body.html", 1)

HTH
Cordially
Pascal
 
G

Guest

Thanks everybody por the answers!

I solved my problem using
..HTMLFormat
..text = file

that "file" is the code read from the .doc file saved as html file.


"Michael Bauer" escreveu:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top