Sending graphics/rich formatting in Outlook

B

Bob

Hi all !!!

I have been assigned the task of sending Word docs out as outlook
emails through VBA. They have rich text and/or graphics in them and
they want them embedded in the emails (no attachments). The techinque
I am using is to automate Word and copy the documents contents to the
clipboard, however when I paste them back into the email, most if not
all of the formatting is gone. I need some ideas on how I can get them
into the emails in their original forms.

Thanks in adavnce.

-- Robert
 
B

Bob

Have you tried the "Office envelope" technique demonstrated athttp://www.outlookcode.com/codedetail.aspx?id=1333?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54








- Show quoted text -

Thanks Sue and Michael.

I am banging my head against the wall on this trying to get a whole
solution, I have gotten parts to work but not all.

Here is some additional information I culled from the people
requesting this functionality, they want the Outlook message to be
displayed but not sent automatically, so they can alter the email if
they want, then send it on their own. And they want to be able to copy
an emails content and save it as a document,including graphics, to use
in a future email. I have gotten everything to save into a Word from
an email except the graphics, but when I paste it back into Outlook
all of the formatting is gone again. I can save emails with formatted
text fine, just not graphics. Also, everything is late binding since I
cannot guarentee which version of Outlook, Word, or Excel they have,
and they do not want to install anything new, they just want to copy
it and it works. So maybe what I am trying to do won't happen without
installing additonal MS or 3rd party software.

Sue - yes I did look at the 'Office envelope' technique, but if my
understanding of it is correct it will not allow the Outlook message
to be displayed and sent manually, or am I wrong on that.

Michael - can you point me to a code example of the Inspector's
WordEditor, I have been playing with the online help and thus far an
having issues with it. Can I set Outlook to use Word as the editor,
produce the emails, then set it back to whatever it was. Since I
cannot control what each user has their editoer set to
 
S

Sue Mosher [MVP-Outlook]

Sue - yes I did look at the 'Office envelope' technique, but if my
understanding of it is correct it will not allow the Outlook message
to be displayed and sent manually, or am I wrong on that.

If you display the Word document, the message is in the intro section.
Can I set Outlook to use Word as the editor,
produce the emails, then set it back to whatever it was. Since I
cannot control what each user has their editoer set to

No, that's not possible.
Also, everything is late binding since I
cannot guarentee which version of Outlook, Word, or Excel they have,

VBA code shouldn't require late binding. Are users capable of at least adding a reference?
 
B

Bob

If you display the Word document, the message is in the intro section.


No, that's not possible.


VBA code shouldn't require late binding. Are users capable of at least adding a reference?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54










- Show quoted text -

Sue:

I just got off the phone with Ken Getz and he said to say "hi"

anyway .......

Here is what I am trying to do: From Excel, I want to open an existing
Word document, and email it using Outlook.

I get an Outlook item open, get the Word doc open, seem to get the
Word contents copied into the Inspector, but can not get them to paste
into the Outlook item for sending.

I have the following code, I am so close but just cannot seem to
figure out what I am doing wrong. I got the orignal routine off the
outlook group website

Sub SendSelectedEmail()

' --- outlook variables
Dim olApp As Outlook.Application ' --- Outlook app
Dim oItem As Outlook.MailItem ' --- Outlook item
Dim bNewOut As Boolean ' --- is Outlook started new

' --- Word variables
Dim wd As Word.Application ' --- Word app
Dim wdDoc As Word.Document ' --- Word doc
Dim bNewWd As Boolean ' --- is Word started new
Dim strFN As String ' --- used for file name of Word file to open

' --- assume outlook is already open
bNewOut = False
bNewWd = False
On Error Resume Next

'
------------------------------------------------------------------------
' --- OUTLOOK STARTUP
----------------------------------------------------
'
------------------------------------------------------------------------

' --- Start Outlook if it isn't running
Set olApp = GetObject(, "Outlook.Application")

If Err <> 0 Then ' --- outlook is not running, start it
Err.Clear
Set olApp = CreateObject("Outlook.Application")
bNewOut = True
End If

'
------------------------------------------------------------------------
' --- WORD STARTUP
-------------------------------------------------------
'
------------------------------------------------------------------------

' --- Start Word if it isn't running
Set wd = GetObject(, "Word.Applcation")

If Err.Number <> 0 Then ' --- open new copy of word
Err.Clear
Set wd = CreateObject("Word.Application")
bNewWd = True
End If

' --- Create a new message and display that message
Set oItem = olApp.CreateItem(olMailItem)

' --- Put a message in at the top of the body
Dim msgIntro As String
' --- used to be an inputbox, I just put in a stock statement to
bypass inputbox
'msgIntro = InputBox("Write a short intro to put above your
default " & _
"signature and current document." & vbCrLf & vbCrLf & _
"Press Cancel to create the mail without intro and " & _
"signature.", "Intro")
' --- put it in by hand
msgIntro = "***** Thsi is a test of the inspector system ******"

' --- open the Word file that is to be sent
strFN = ThisWorkbook.Path & "\Emails\" & Me.lstFolders.Value & "\"
& Me.lstEmails.Text

' --- open the word doc
Set wdDoc = wd.Documents.Open(FileName:=strFN, Visible:=True)

' --- Copy the open document
wd.Selection.WholeStory
wd.Selection.Copy
wd.Selection.End = True

' --- Set the Outlook Inspector/WordEditor
Dim objInsp As Outlook.inspector

Set objInsp = oItem.GetInspector
Set wdDoc = objInsp.WordEditor

' --- Write the intro if specified
Dim i As Integer
If msgIntro = IsNothing Then
i = 1
' --- Comment the next line to leave your default
signature below the document
wdDoc.Content.Delete
Else
' --- Write the intro above the signature
wdDoc.Characters(1).InsertBefore (msgIntro)
i = wdDoc.Characters.Count
wdDoc.Characters(i).InlineShapes.AddHorizontalLineStandard
wdDoc.Characters(i + 1).InsertParagraph

i = i + 2
End If

' --- Place the current document under the intro and signature
wdDoc.Characters(i).PasteAndFormat (wdFormatOriginalFormatting)

' --- Display the message
oItem.Display

'
------------------------------------------------------------------------
' --- Clean up
'
------------------------------------------------------------------------

' --- clean up Outlook
If bNewOut = True Then
olApp.Quit
End If

Set oItem = Nothing
Set olApp = Nothing

' --- clean up Word
If bNewWd = True Then
wd.Quit
End If

Set wd = Nothing
Set wdDoc = Nothing

' --- clean up Inspector
Set objInsp = Nothing
Set wdEditor = Nothing


End Sub
 
B

Bob

If you display the Word document, the message is in the intro section.
No, that's not possible.
VBA code shouldn't require late binding. Are users capable of at least adding a reference?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Bob said:
On Jul 4, 8:05 am, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Have you tried the "Office envelope" technique demonstrated athttp://www.outlookcode.com/codedetail.aspx?id=1333?
Hi all !!!
I have been assigned the task of sending Word docs out as outlook
emails through VBA. They have rich text and/or graphics in them and
they want them embedded in the emails (no attachments). The techinque
I am using is to automate Word and copy the documents contents to the
clipboard, however when I paste them back into the email, most if not
all of the formatting is gone. I need some ideas on how I can get them
into the emails in their original forms.
Thanks in adavnce.
-- Robert- Hide quoted text -
- Show quoted text -
Thanks Sue and Michael.
I am banging my head against the wall on this trying to get a whole
solution, I have gotten parts to work but not all.
Here is some additional information I culled from the people
requesting this functionality, they want the Outlook message to be
displayed but not sent automatically, so they can alter the email if
they want, then send it on their own. And they want to be able to copy
an emails content and save it as a document,including graphics, to use
in a future email. I have gotten everything to save into a Word from
an email except the graphics, but when I paste it back into Outlook
all of the formatting is gone again. I can save emails with formatted
text fine, just not graphics. Also, everything is late binding since I
cannot guarentee which version of Outlook, Word, or Excel they have,
and they do not want to install anything new, they just want to copy
it and it works. So maybe what I am trying to do won't happen without
installing additonal MS or 3rd party software.
Sue - yes I did look at the 'Office envelope' technique, but if my
understanding of it is correct it will not allow the Outlook message
to be displayed and sent manually, or am I wrong on that.
Michael - can you point me to a code example of the Inspector's
WordEditor, I have been playing with the online help and thus far an
having issues with it. Can I set Outlook to use Word as the editor,
produce the emails, then set it back to whatever it was. Since I
cannot control what each user has their editoer set to- Hide quoted text -
- Show quoted text -

Sue:

I just got off the phone with Ken Getz and he said to say "hi"

anyway .......

Here is what I am trying to do: From Excel, I want to open an existing
Word document, and email it using Outlook.

I get an Outlook item open, get the Word doc open, seem to get the
Word contents copied into the Inspector, but can not get them to paste
into the Outlook item for sending.

I have the following code, I am so close but just cannot seem to
figure out what I am doing wrong. I got the orignal routine off the
outlook group website

Sub SendSelectedEmail()

' --- outlook variables
Dim olApp As Outlook.Application ' --- Outlook app
Dim oItem As Outlook.MailItem ' --- Outlook item
Dim bNewOut As Boolean ' --- is Outlook started new

' --- Word variables
Dim wd As Word.Application ' --- Word app
Dim wdDoc As Word.Document ' --- Word doc
Dim bNewWd As Boolean ' --- is Word started new
Dim strFN As String ' --- used for file name of Word file to open

' --- assume outlook is already open
bNewOut = False
bNewWd = False
On Error Resume Next

'
------------------------------------------------------------------------
' --- OUTLOOK STARTUP
----------------------------------------------------
'
------------------------------------------------------------------------

' --- Start Outlook if it isn't running
Set olApp = GetObject(, "Outlook.Application")

If Err <> 0 Then ' --- outlook is not running, start it
Err.Clear
Set olApp = CreateObject("Outlook.Application")
bNewOut = True
End If

'
------------------------------------------------------------------------
' --- WORD STARTUP
-------------------------------------------------------
'
------------------------------------------------------------------------

' --- Start Word if it isn't running
Set wd = GetObject(, "Word.Applcation")

If Err.Number <> 0 Then ' --- open new copy of word
Err.Clear
Set wd = CreateObject("Word.Application")
bNewWd = True
End If

' --- Create a new message and display that message
Set oItem = olApp.CreateItem(olMailItem)

' --- Put a message in at the top of the body
Dim msgIntro As String
' --- used to be an inputbox, I just put in a stock statement to
bypass inputbox
'msgIntro = InputBox("Write a short intro to put above your
default " & _
"signature and current document." & vbCrLf & vbCrLf & _
"Press Cancel to create the mail without intro and " & _
"signature.", "Intro")
' --- put it in by hand
msgIntro = "***** Thsi is a test of the inspector system ******"

' --- open the Word file that is to be sent
strFN = ThisWorkbook.Path & "\Emails\" & Me.lstFolders.Value & "\"
& Me.lstEmails.Text

' --- open the word doc
Set wdDoc = wd.Documents.Open(FileName:=strFN, Visible:=True)

' --- Copy the open document
wd.Selection.WholeStory
wd.Selection.Copy
wd.Selection.End = True

' --- Set the Outlook Inspector/WordEditor
Dim objInsp As Outlook.inspector

Set objInsp = oItem.GetInspector
Set wdDoc = objInsp.WordEditor

' --- Write the intro if specified
Dim i As Integer
If msgIntro = IsNothing Then
i = 1
' --- Comment the next line to leave your default
signature below the document
wdDoc.Content.Delete
Else
' --- Write the intro above the signature
wdDoc.Characters(1).InsertBefore (msgIntro)
i = wdDoc.Characters.Count
wdDoc.Characters(i).InlineShapes.AddHorizontalLineStandard
wdDoc.Characters(i + 1).InsertParagraph

i = i + 2
End If

' --- Place the current document under the intro and signature
wdDoc.Characters(i).PasteAndFormat (wdFormatOriginalFormatting)

' --- Display the message
oItem.Display

'
------------------------------------------------------------------------
' --- Clean up
'
------------------------------------------------------------------------

' --- clean up Outlook
If bNewOut = True Then
olApp.Quit
End If

Set oItem = Nothing
Set olApp = Nothing

' --- clean up Word
If bNewWd = True Then
wd.Quit
End If

Set wd = Nothing
Set wdDoc = Nothing

' --- clean up Inspector
Set objInsp = Nothing
Set wdEditor = Nothing

End Sub- Hide quoted text -

- Show quoted text -

I got it to work. I was using different versions of Outlook and Word,
once I installed the same version this works fine now
 

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