PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Pasting from Word 2002 to Outlook 2003
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Pasting from Word 2002 to Outlook 2003
![]() |
Pasting from Word 2002 to Outlook 2003 |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
How can I can capture (replicate programatically) the act of copying
the body of a Word document to an Outlook message? Thanks. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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? -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Namgaw" <jameswagman@gmail.com> wrote in message news:be8c6e49-c35e-437e-8113-b0fa2e0d9f39@i12g2000prf.googlegroups.com... > How can I can capture (replicate programatically) the act of copying > the body of a Word document to an Outlook message? > > Thanks. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
On 6 Dec, 10:13, "Ken Slovak - [MVP - Outlook]" <kenslo...@mvps.org>
wrote: > 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? > > -- > Ken Slovak > [MVP - Outlook]http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm > > "Namgaw" <jameswag...@gmail.com> wrote in message > > news:be8c6e49-c35e-437e-8113-b0fa2e0d9f39@i12g2000prf.googlegroups.com... > > > > > How can I can capture (replicate programatically) the act of copying > > the body of a Word document to an Outlook message? > > > Thanks.- Hide quoted text - > > - 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 = "jwagman@foxpitt.com" 'Set the recipient for a copy .CC = "jwagman@foxpitt.com" '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. |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Namgaw" <jameswagman@gmail.com> wrote in message news:9c39c9cf-3cd2-4e42-b052-5cadcb92cede@t47g2000hsc.googlegroups.com... <snip> > 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 = "jwagman@foxpitt.com" > 'Set the recipient for a copy > .CC = "jwagman@foxpitt.com" > '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. |
|
|
|
#5 |
|
Guest
Posts: n/a
|
On 6 Dec, 16:11, "Ken Slovak - [MVP - Outlook]" <kenslo...@mvps.org>
wrote: > 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. > > -- > Ken Slovak > [MVP - Outlook]http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm > > "Namgaw" <jameswag...@gmail.com> wrote in message > > news:9c39c9cf-3cd2-4e42-b052-5cadcb92cede@t47g2000hsc.googlegroups.com... > <snip> > > > > > 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 = "jwag...@foxpitt.com" > > 'Set the recipient for a copy > > .CC = "jwag...@foxpitt.com" > > '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.- Hide quoted text - > > - Show quoted text - No luck on that. Any other suggestions? |
|
|
|
#6 |
|
Guest
Posts: n/a
|
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. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Namgaw" <jameswagman@gmail.com> wrote in message news:dca7757f-9a51-4ad8-abad-df605f0882bb@t47g2000hsc.googlegroups.com... <snip> > No luck on that. Any other suggestions? |
|
|
|
#7 |
|
Guest
Posts: n/a
|
On Dec 7, 9:39 am, "Ken Slovak - [MVP - Outlook]" <kenslo...@mvps.org>
wrote: > 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. > > -- > Ken Slovak > [MVP - Outlook]http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm > > "Namgaw" <jameswag...@gmail.com> wrote in message > > news:dca7757f-9a51-4ad8-abad-df605f0882bb@t47g2000hsc.googlegroups.com... > <snip> > > > > > No luck on that. Any other suggestions?- Hide quoted text - > > - 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. |
|
|
|
#8 |
|
Guest
Posts: n/a
|
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> </DIV> <DIV> </DIV> <DIV> </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. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Namgaw" <jameswagman@gmail.com> wrote in message news:bcacc50a-5eff-4883-b075-ccb6ca3d0340@s19g2000prg.googlegroups.com... <snip> > Hmmm, I'm a newbie w/Outlook VBA and HTML. Could you give me a small > sample of what you're proposing? Thanks. |
|
|
|
#9 |
|
Guest
Posts: n/a
|
On Dec 8, 1:24 pm, "Ken Slovak - [MVP - Outlook]" <kenslo...@mvps.org>
wrote: > 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> </DIV> > <DIV> </DIV> > <DIV> </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. > -- > Ken Slovak > [MVP - Outlook]http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm > > "Namgaw" <jameswag...@gmail.com> wrote in message > > news:bcacc50a-5eff-4883-b075-ccb6ca3d0340@s19g2000prg.googlegroups.com... > <snip> > > > > > Hmmm, I'm a newbie w/Outlook VBA and HTML. Could you give me a small > > sample of what you're proposing? Thanks.- Hide quoted text - > > - Show quoted text - Let's say I did have Word 2003 and Outlook2003, what can I do with wordmail? Thanks! |
|
|
|
#10 |
|
Guest
Posts: n/a
|
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. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Namgaw" <jameswagman@gmail.com> wrote in message news:6bab567b-167b-4722-9f85-5a6c5446a8ff@e23g2000prf.googlegroups.com... <snip> > Let's say I did have Word 2003 and Outlook2003, what can I do with > wordmail? Thanks! |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

