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.
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.
- Sub Mail_Consolidation()
- Dim WordApp As Word.Application 'Need to link Microsoft Word Object library, Oulook library from Tools->References\
- Dim wdDoc As Word.Document 'for these to be understood by compiler
- Dim activeMailMessage As Outlook.MailItem
- Dim activeBody As String
- 'Dim X As String
- Selection.HomeKey Unit:=wdStory
- Selection.WholeStory
- Selection.Delete Unit:=wdCharacter, Count:=1
- 'On Error Resume Next
- 'Inputbox to get the count of emails selected in folder
- 'X = InputBox(Prompt:="Number of Mails Selected is ", Title:="Number of Mails", Default:="")
- For i = 1 To 21
- If TypeName(ActiveExplorer.Selection.Item(i)) = "MailItem" Then
- 'Goes to Outlook mails
- Set activeMailMessage = ActiveExplorer.Selection.Item(i)
- 'Copy the formatted text from selected mails:
- activeMailMessage.GetInspector().WordEditor.Range.FormattedText.Copy
- 'Paste to the word document
- Selection.Paste 'AndFormat (wdFormatOriginalFormatting)
- Selection.EndKey Unit:=wdStory
- Selection.TypeParagraph
- End If
- Next
- ActiveDocument.Save
- 'ActiveDocument.Close
- MsgBox "Mail Consolidation is Done"
- End Sub