Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paste document section into email

Status
Not open for further replies.

grannyM

Programmer
Nov 26, 2002
39
0
0
US
Using Visual Basic template in Word, I am currently creating an email to be sent to a specific department. I'm using redemption to create the email and I'd like to pull a section of the document created from the template into the body of the email. I'd prefer not to create a separate document to be attached to the email. I've tried retrieving the contents of a bookmark:

Code:
activedocument.bookmarks("Routing_Slip").range.text
Code:

and it works, but it does not retain the formatting or the bullets on the original document. Without code, I can highlight the section, copy, select the open email, paste, and it pastes beautifully.

Is there anyway (using vba code) to select the body of the created email and just paste text into it? Here is my code for the redemption function itself:

Code:
Function SendEmail()

Dim SafeItem, oItem, ccRecipient As Object
Dim olapp As Outlook.Application
Dim nspnamespace As Outlook.NameSpace

Set olapp = Outlook.Application
Set nspnamespace = olapp.GetNamespace("Mapi")
Set SafeItem = CreateObject("outlook.SafeMailItem")
Set oItem = olapp.CreateItem(0)

SafeItem.Item = oItem
SafeItem.Recipients.Add "supportdepartment"
SafeItem.Recipients.ResolveAll
SafeItem.Subject = "Amendment Routing Sheet"
Selection.Paste

Set olapp = Nothing
Set nspnamespace = Nothing
Set SafeItem = Nothing
Set oItem = Nothing

End Function

Code:

Or does anyone have any other ideas?

Thanks for your help
 
Have tried something like this ?
ActiveDocument.Bookmarks("Routing_Slip").Range.FormattedText.Copy

Hope This Help
PH.
 
Thank you for your help, but that didn't work either. Looks like I have no choice but to have the macro paste the selection to a new document then attach that document. I was hoping that someone with Outlook macroing experience would be able to tell me how to select the open email and paste into the body. Thanks for trying!
 
I use this to insert a range of an excel sheet into the body of the email an email it.

Public Sub Email()

Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim FSObj As Scripting.FileSystemObject
Dim TStream As Scripting.TextStream
Dim rngeSend As Range
Dim strHTMLBody As String


'Select the range to be sent
Set rngeSend = Application.Range("A1:C34")
If rngeSend Is Nothing Then Exit Sub
On Error GoTo 0

'Now create the HTML file
ActiveWorkbook.PublishObjects.Add(xlSourceRange, "C:\temp\tempsht.htm", rngeSend.Parent.Name, rngeSend.Address, xlHtmlStatic).Publish True


'Create an instance of Outlook (or use existing instance if it already exists
Set olApp = CreateObject("Outlook.Application")

'Create a mail item
Set olMail = olApp.CreateItem(olMailItem)

'Open the HTML file using the FilesystemObject into a TextStream object
Set FSObj = New Scripting.FileSystemObject
Set TStream = FSObj.OpenTextFile("C:\temp\tempsht.htm", ForReading)

'Now set the HTMLBody property of the message to the text contained in the TextStream object
strHTMLBody = TStream.ReadAll

olMail.HTMLBody = strHTMLBody
olMail.To = "joe@anywhere.com"
olMail.Subject = "Automatic Excel Email"
olMail.Send


End Sub
 
Is there a reference I need to turn on for this to work? I'm not familiar with "Scripting" and my code doesn't recognize it.
 
Microsoft Script Control 1.0
Microsoft Scripting Runtime
 
Ok, I turned those references on, and then where the HTML file is created flagged as an error. I tried turning on Microsoft HTML Object Library but that didn't help. It doesn't like PublishObjects.

Sorry, I've been programming in VBA for about a year and a half now and haven't used the scripting or the HTML. I'm always exited to learn new things, but don't want to take any more of your time then necessary. Perhaps you can point me to some reference materials.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top