Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attach email to Word Document

Status
Not open for further replies.

grannyM

Programmer
Nov 26, 2002
39
0
0
US
If you have Word and Outlook open side-by-side, you can drag an email into the Word document. It inserts an envelope icon that opens the email when you double-click on it.

I'm trying to do this samething through code. I can get it to the point where the correct outlook folder is open on the screen and the macro pauses to allow the user to select the email(s) needed. However, I have not been able to figure out how to then copy the selected email(s) into the open Word document. Any help is appreciated.

Here is my code so far:

Code:
Function OutlookFolder()
Dim olapp As Outlook.Application   'Allows access to MS Outlook Application object
Dim ons As Outlook.NameSpace       'Programming Interface Object
Dim mypublic As Outlook.MAPIFolder 'Set Variable to folders collection
Dim mysent As Outlook.MAPIFolder   'Set Variable to folders collection
Dim myitems
Dim myitem 
Dim PauseTime, Start, Finish, TotalTime

Set olapp = CreateObject("Outlook.Application")
Set ons = olapp.GetNamespace("MAPI")
Set mypublic = ons.Folders("Public Folders").Folders("All Public Folders").Folders("Client Folders").Folders(PlanRef$ & " " & CoName$).Folders(PlanRef$ & " Admin Correspondence")

MsgBox "Select email(s) to be copied, then click on ok", vbOKOnly, "Macro 2-500"

mypublic.Display   'Use this to Test opening the folder to public folder

PauseTime = 5   'set duration
Start = Timer   'set start time
Do While Timer < Start + PauseTime
    DoEvents    'Yield to other processes
Loop
Finish = Timer  'set end time

myitem.Copy   [COLOR=red] '(this doesn't work - gives err "Object Required)[/color]

ActiveDocument.Activate


    Selection.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, Placement _
        :=wdInLine, DisplayAsIcon:=True, IconFileName:= _
        "C:\Program Files\Microsoft Office\Office\forms\1033\IPML.ICO", IconIndex _
        :=0, IconLabel:="Package"


Set ons = Nothing
Set mypublic = Nothing
Set mysent = Nothing

End Function
 
You may try to replace this:
myitem.Copy
By this:
olapp.ActiveExplorer.Selection.Item(1).Copy

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PH, but this just makes another copy of the email in the same email folder. It doesn't copy it to the clipboard, so the Paste Special doesn't work. Maybe I need to paste or attach it into the word Document a different way? and I really don't want another copy of the email in the folder. Any other ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top