Pasting from Word 2002 to Outlook 2003

  • Thread starter Thread starter Namgaw
  • Start date Start date
N

Namgaw

How can I can capture (replicate programatically) the act of copying
the body of a Word document to an Outlook message?

Thanks.
 
Those are 2 different things. Which do you want to do, trap when a copy from
Word is made to an Outlook item body, or copy text from Word to an Outlook
item body using code?
 
Those are 2 different things. Which do you want to do, trap when a copy from
Word is made to an Outlook item body, or copy text from Word to an Outlook
item body using code?









- Show quoted text -

The latter, i.e. copy text from Word to an Outlook
item body using code. I save the file to filtered HTML. Here is the
code:

Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim myDoc As Document
Dim fileName As String


'On Error Resume Next

ActiveDocument.Bookmarks("stock_code_V").Select
fileName = Selection.Range
fileName = getString(fileName)
ActiveDocument.SaveAs fileName:="H:\Diana\email macros\email tmp\" &
fileName, _
FileFormat:=wdFormatDocument, LockComments:=False,
Password:="", _
AddToRecentFiles:=True, WritePassword:="",
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData _
:=False, SaveAsAOCELetter:=False

'wdformatfilteredhtml

'ActiveDocument.SaveAs fileName:="H:\Diana\email macros\email tmp\" &
fileName, _
FileFormat:=wdFormatRTF, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False,
_
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData _
:=False, SaveAsAOCELetter:=False

Selection.WholeStory


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

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)


ActiveDocument.Bookmarks("stock_code_V").Select
Dim fso As FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
Dim ts As TextStream
Set ts = fso.OpenTextFile("H:\Diana\email macros\email tmp\" &
fileName & ".doc", _
ForReading)

strtext = ts.ReadAll


With oItem
'Set the recipient for the new email
.To = "(e-mail address removed)"
'Set the recipient for a copy
.CC = "(e-mail address removed)"
'Set the subject
.Subject = "FPKCCW: " & Selection.Range & " - Title"
'The content of the document is used as the body for the email
' Selection.WholeStory
' Selection.Copy
Selection.WholeStory
.Body = strtext
' .HTMLBody = strtext
' .HTMLBody = Selection.Range
.Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub
Private Function getString(ByVal Stringin As String) As String
If InStr(1, Stringin, "/") > 0 Then
getString = Replace(Stringin, "/", "")
End If
End Function



What happens is that the mail comes in with everything but the tables,
graphics.
 
See if it works any better if you just get the entire contents of the Word
doc as a string and set Body to that.
 
See if it works any better if you just get the entire contents of the Word
doc as a string and set Body to that.




<snip>
















- Show quoted text -

No luck on that. Any other suggestions?
 
Then I think the only way to do what you want would be to work in HTML and
set the text from Word into HTMLBody using the HTML tags and HTML code and
parsing.
 
Then I think the only way to do what you want would be to work in HTML and
set the text from Word into HTMLBody using the HTML tags and HTML code and
parsing.




<snip>




- Show quoted text -

Hmmm, I'm a newbie w/Outlook VBA and HTML. Could you give me a small
sample of what you're proposing? Thanks.
 
Copy a portion that includes all the formats you want to include from one of
the docs you want to save into a new document and save it as HTML, then open
the htm file using Notepad. That's what the Word HTML looks like. It's badly
formed and horribly verbose but that's what you'll have to deal with.

Then save a blank HTML email message as an HTM file and open that in
Notepad. It will look something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16544" name=GENERATOR></HEAD>
<BODY>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

The <BODY> </BODY> tags are where you have to place your Word text. You'll
have to remove duplicate definitions and place the Word text where you want
it. There are some simple HTML formatting samples for Outlook at
www.outlookcode.com, but if you want to do anything fancy looking you'll
have to do some research on HTML coding to get things the way you want.
You're essentially merging two different HTML sources with non-compatible
formatting.

Things would be easier if you had Word 2003 to go along with Outlook 2003.
Then you could use WordMail and at least the HTML source would be more
compatible although uglier on the WordMail part.
 
Copy a portion that includes all the formats you want to include from one of
the docs you want to save into a new document and save it as HTML, then open
the htm file using Notepad. That's what the Word HTML looks like. It's badly
formed and horribly verbose but that's what you'll have to deal with.

Then save a blank HTML email message as an HTM file and open that in
Notepad. It will look something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16544" name=GENERATOR></HEAD>
<BODY>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

The <BODY> </BODY> tags are where you have to place your Word text. You'll
have to remove duplicate definitions and place the Word text where you want
it. There are some simple HTML formatting samples for Outlook atwww.outlookcode.com, but if you want to do anything fancy looking you'll
have to do some research on HTML coding to get things the way you want.
You're essentially merging two different HTML sources with non-compatible
formatting.

Things would be easier if you had Word 2003 to go along with Outlook 2003.
Then you could use WordMail and at least the HTML source would be more
compatible although uglier on the WordMail part.



<snip>




- Show quoted text -

Let's say I did have Word 2003 and Outlook2003, what can I do with
wordmail? Thanks!
 
Having the same version of Word and Outlook will let you use WordMail and
the HTML will be compatible between the two HTML sources. You'll still have
to parse the HTML and insert the Word document but it would be easier than
trying to insert Word HTML into Outlook editor HTML, that's all.
 
Back
Top