View Single Post
  #2   Report Post  
Posted to microsoft.public.word.docmanagement,microsoft.public.word.vba.general
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Using Word I want to create a file including graphics to use in Em

Coincidentally I have been working with fellow MVPs to produce a macro that
does something similar. The resulting code is:

Sub Send_Extract_As_EMail()
' send the document in an Outlook Email message
' 2007 Graham Mayor, Tony Jollans, Doug Robbins
' & Sue Mosher

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim objDoc As Word.Document
Dim strEMail As String

strEMail = "PR_EMAIL_ADDRESS"
'Let the user choose the contact from Outlook
'And assign the email address to a variable

strEMail = Application.GetAddress("", strEMail, _
False, 1, , , True, True)
If strEMail = "" Then
MsgBox "User cancelled or no address listed", , "Cancel"
End If

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")

'Outlook wasn't running, start it from code
If Err 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
Set objDoc = oItem.GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection

With oItem
.to = strEMail
.Subject = InputBox("Subject?")
Selection.Copy
.Display
objSel.Paste
End With

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

This will copy selected formatted text including in-line graphics and puts
them in the body of an Outlook e-mail message. For me, it only works
reliably when Outlook is already open - you can see the thread in the
microsoft.public.word.vba.general group. Formatting in Word and the message
body will be affected by the differing requirements of HTML and Word
Document format.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




AWIcurrent wrote:
I want to create a file with graphics and pictures which can then be
read in VB 2005 and put into an email by setting the message= to the
content of that file.

Said in another way. I want to use Word to create email message
content full of pictures and so on and then save it for reading into
a VB 2005 program and setting the message portion = to the file
content.

This code is working great for text files. Richtext files from word
are not doing well with the pictures nor are HTML saves from WORD.

I am using system.net.mail and the message is being set as
mailmsg.body= to the content of the file read into a string variable.
Should I just set the body equal to the file rather than making it
into a string variable? Body appears to be a string type so this
should work. I am setting the mailmsg.html to true so I would think
it would decode correctly...but what do i know!

Should the body be a type other than a string? perhaps this should
just be an object but then will the mailmsg.body accept that variable
type?

What is the correct way to save this from Word so that it can be used
as planned?

Thank you.