Hello Everyone,

I need some help on the below script. The below script is consolidating the mail body contents from the selected mails to MS Word Document. I am getting an error message on the line no. 35 as "Runtime Error 4605" "This Property or method is not available because the clipboard is not empty or not valid. If I put "'On Error Resume Next" to bypass this error message, then I am not getting all the contents of all selected mails. Your vaulable advise will help me a lot.

  1. Sub Mail_Consolidation()
  2. Dim WordApp As Word.Application 'Need to link Microsoft Word Object library, Oulook library from Tools->References\
  3. Dim wdDoc As Word.Document 'for these to be understood by compiler
  4. Dim activeMailMessage As Outlook.MailItem
  5. Dim activeBody As String
  6. 'Dim X As String
  7. Selection.HomeKey Unit:=wdStory
  8. Selection.WholeStory
  9. Selection.Delete Unit:=wdCharacter, Count:=1
  10. 'On Error Resume Next
  11. 'Inputbox to get the count of emails selected in folder
  12. 'X = InputBox(Prompt:="Number of Mails Selected is ", Title:="Number of Mails", Default:="")
  13. For i = 1 To 21
  14. If TypeName(ActiveExplorer.Selection.Item(i)) = "MailItem" Then
  15. 'Goes to Outlook mails
  16. Set activeMailMessage = ActiveExplorer.Selection.Item(i)
  17. 'Copy the formatted text from selected mails:
  18. activeMailMessage.GetInspector().WordEditor.Range.FormattedText.Copy
  19. 'Paste to the word document
  20. Selection.Paste 'AndFormat (wdFormatOriginalFormatting)
  21. Selection.EndKey Unit:=wdStory
  22. Selection.TypeParagraph
  23. End If
  24. Next
  25. ActiveDocument.Save
  26. 'ActiveDocument.Close
  27. MsgBox "Mail Consolidation is Done"
  28. End Sub