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:
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