| Code level: intermediate Code area: Outlook Expert Techniques Printer Friendly Version | ||
| Title: OL2007: Copy formatted body between items | ||
| Description: This sample takes advantage of Word being the editor for all Outlook 2007 items except sticky notes and distribution lists. | ||
| Date: 03-Jul-2009 10:13 | ||
| Code level: intermediate | ||
| Code area: Outlook Expert Techniques | ||
| Posted by: Sue Mosher | ||
| Body: |
||
| All 6comments |
| Page [ 1 ] | ||
|
|
Sue Mosher
03-Jul-2009 10:14
Typical usage of this code would be to copy the body from an existing item to a new item, for example, copying from a message to a new task: Sub TestCopyFullBody() Dim objMsg As Outlook.MailItem Dim objTask As Outlook.TaskItem Set objMsg = Application.ActiveExplorer.Selection(1) Set objTask = Application.CreateItem(olTaskItem) Call CopyFullBody(objMsg, objTask) objTask.Display Set objMsg = Nothing Set objTask = Nothing End Sub |
|
|
|
Kolzw
05-Jul-2009 15:38
Hi Sue, thanks for the help.. Rookie though.... what am i doing wrong Sub TestCopyFullBody() Dim objMsg As Outlook.MailItem Dim objTask As Outlook.TaskItem Set objMsg = Application.ActiveExplorer.Selection(1) Set objTask = Application.CreateItem(olTaskItem) Call CopyFullBody(objMsg, objTask) objTask.Display Set objMsg = Nothing Set objTask = Nothing End Sub Sub CopyFullBody(sourceItem As Object, targetItem As Object) Dim objDoc As Word.Document Dim objSel As Word.Selection Dim objDoc2 As Word.Document Dim objSel2 As Word.Selection On Error Resume Next ' get a Word.Selection from the source item Set objDoc = sourceItem.GetInspector.WordEditor If Not objDoc Is Nothing Then Set objSel = objDoc.Windows(1).Selection objSel.WholeStory objSel.Copy Set objDoc2 = targetItem.GetInspector.WordEditor If Not objDoc2 Is Nothing Then Set objSel2 = objDoc2.Windows(1).Selection objSel2.PasteAndFormat wdPasteDefault Else MsgBox "Could not get Word.Document for " & _ targetItem.Subject End If Else MsgBox "Could not get Word.Document for " & _ sourceItem.Subject End If Set objDoc = Nothing Set objSel = Nothing Set objDoc2 = Nothing Set objSel2 = Nothing End Sub |
|
|
|
Sue Mosher
05-Jul-2009 16:47
Kolzw, what actually happens when you run the code in Outlook VBA? You may want to comment out the On Error statement so you can see any errors more easily. |
|
|
|
S Baker
27-Jul-2009 18:37
I attempted to use the Sub CopyFullBody, but when I call it I receive a Compile error: User-defined type not defined On the first line of the Sub Dim objDoc As Word.Document Any assistance is appreciated. |
|
|
|
Sue Mosher
27-Jul-2009 18:39
S, you need to add a reference to the Microsoft Word programming library. In VBA, use Tools | References. |
|
|
|
Anonymous
27-Jul-2009 19:16
Thank you, that did the trick. I hope I eventually catch on the this stuff. Love the site. |
|
| Page [ 1 ] | ||
| Post your comment name email |
