Consulting

Results 1 to 4 of 4

Thread: Solved: Copying an entire Letter from word document

  1. #1

    Solved: Copying an entire Letter from word document

    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:

    [vba]
    TempString = wrdDoc.Bookmarks("GetData").Range.Text
    ReDim Preserve myArray(j)
    myArray(j) = TempString
    [/vba]


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

  2. #2
    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...

  3. #3
    I'm not sure how that would work programatically. Or what code to use to do that.

  4. #4
    Got it.

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

    [vba]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[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •