#1
|
|||
|
|||
copy and paste Outlook Email bodytext to Word document
It sounds pretty simple. I am trying to create copy Outlook’s e-mail bodytext with "Match Destination Formatting" to a placeholder text in a Word document.
I have been trying for hours to record different workflows. None of them are working. I am using Office 2003 and VB 6.5 Here’s my VBA code. Public Sub CopyPaste() Selection.Copy Dim objDoc As Word.Document Selection.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis) Set objDoc = Nothing Set objSel = Nothing End Sub Where can I download templates for this simple workflow? Thank you any advice or help. |
#2
|
||||
|
||||
It has been a while since I programmed for Outlook 2003, but provided you have Outlook configured with Word as its editor and you have the message opened in the editor, with the required text selected, the following should copy that selected text to a bookmarked location (here bmMessageText) in a named document ("C:\Path\DocumentName.doc"), but I don't have Outlook 2003 available to check it. The macro uses the requested wdFormatSurroundingFormattingWithEmphasis (20), but I might be more inclined to use plain text (2) which will adopt the format at the insertion point.
Code:
Option Explicit Sub CopyMessage() Dim wdApp As Object Dim objDoc As Object Dim oBM As Object Dim bFound As Boolean On Error GoTo err_Handler If TypeName(ActiveWindow) = "Inspector" Then If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then ActiveInspector.WordEditor.Application.Selection.Copy Else MsgBox "Nothing to copy" GoTo lbl_Exit End If Else MsgBox "Nothing to copy" GoTo lbl_Exit End If On Error Resume Next Set wdApp = GetObject(, "Word.Application") If Err Then Set wdApp = CreateObject("Word.Application") End If On Error GoTo err_Handler Set objDoc = wdApp.Documents.Open("C:\Path\DocumentName.doc") wdApp.Visible = True wdApp.Activate For Each oBM In objDoc.bookmarks If oBM.Name = "bmMessageText" Then oBM.Range.PasteSpecial DataType:=20 bFound = True Exit For End If Next oBM If Not bFound Then MsgBox ("Bookmark name 'bmMessageText' not found.") GoTo lbl_Exit End If objDoc.Save lbl_Exit: Set objDoc = Nothing Set wdApp = Nothing Exit Sub err_Handler: MsgBox "Uncorrected error number " & Err.Number & vbCr & _ Err.Description GoTo lbl_Exit End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How can I let my users copy and paste into a protected Word Document? | moden9999 | Word | 4 | 02-02-2015 05:39 PM |
Is it possible to copy & paste Table of Contents out of one document into another? | mikey386 | Word | 4 | 12-18-2014 08:45 AM |
copy from web and paste in a word document : no images are shown | Ron Wolpa | Word | 5 | 09-11-2013 02:16 AM |
Can no longer copy and paste an email file into a task | kc300c | Outlook | 0 | 07-16-2010 04:34 PM |
Copy the contents of a dcoument and paste it several times in a new document | Gerjanst | Word VBA | 0 | 06-30-2010 12:51 PM |