PDA

View Full Version : Solved: Copying an entire Letter from word document



DanOfEarth
06-02-2010, 06:37 PM
In Excel, I've got a button in a telephone prospect list that will fire up Outlook and shoot out an email using the text written on a spreadsheet as the "body".

It's a bit sloppy. I'd like to copy the entire "body"....formatting and all....out of a word doc instead. I've got all the code to do this, but I'm rigging it a bit.

I've highlighted the whole text part, "bookmarked it" named Get Data, and wrote the following code:


TempString = wrdDoc.Bookmarks("GetData").Range.Text
ReDim Preserve myArray(j)
myArray(j) = TempString



But I don't think it saves the formatting. Anybody know of a better way. The text includes several paragraphs, etc.

Shred Dude
06-02-2010, 09:00 PM
In your code the creates the Outlook mail message, are you using the .Body property, or the .HTMLBody property?

If the latter, perhaps you might try saving your text that you've prepared in Word as an .htm file, and then reading that entire file's contents into a variable that you'd assign to the HTMLBody property in your mail message.

I'm not sure that the formatting would remain in the regular .Body property. Isn't that just text?

Hope that can help...

DanOfEarth
06-03-2010, 03:40 AM
I'm not sure how that would work programatically. Or what code to use to do that.

DanOfEarth
06-03-2010, 09:51 AM
Got it.

This is some cool stuff. Had to use the "doc.MailEnvelope.Item" method.

Sub SendDocAsMsg()
Dim wd As Object
Dim doc As Object
Dim itm As Object
Dim ID As String
Dim blnWeOpenedWord As Boolean
On Error Resume Next

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(Filename:="C:\Documents and Settings\Dan\Desktop\SHORT SELL\Email1.docx", ReadOnly:=True)
Set itm = doc.MailEnvelope.Item
With itm
.To = "d.blass@yahoo.com"
.Subject = "Testing another document with format"
.Save
ID = .EntryID
End With

Set itm = Application.Session.GetItemFromID(ID)
itm.Send
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If

Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub