Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-25-2015, 02:32 PM
eYos eYos is offline copy and paste Outlook Email bodytext to Word document Windows XP copy and paste Outlook Email bodytext to Word document Office 2003
Novice
copy and paste Outlook Email bodytext to Word document
 
Join Date: Aug 2015
Posts: 1
eYos is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 08-25-2015, 09:41 PM
gmayor's Avatar
gmayor gmayor is offline copy and paste Outlook Email bodytext to Word document Windows 7 64bit copy and paste Outlook Email bodytext to Word document Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft