-
outlook vba
Hi,
I tried to run the following code in outlook 2003. But i am getting error "Run time rror 424; object required" at line item.Body.Select. Could some one please help me what is the issue?
Sub savedailyownership()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim myitem As Outlook.MailItem
Dim FileName As String
Dim i As Integer
Dim objSearchFolder As Outlook.MAPIFolder
Dim item As Object
Dim mai As MailItem
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set objSearchFolder = Inbox
i = 0
If Inbox.Items.Count = 0 Then
MsgBox "Inbox is Empty", vbInformation, "Nothing Found"
End If
For Each item In Inbox.Items
If item.Subject Like "Test outlook-Excel" Then
'item.Display
item.Body.Select
Selection.Copy
Dim xlApp As Object ' Excel.Application
Dim xlWkb As Object ' Excel.Workbook
Set xlApp = CreateObject("Excel.Application") ' New Excel.Application
Set xlWkb = xlApp.Workbooks.Add
xlApp.Visible = True
xlApp.Workbooks.Add
xlApp.Selection.Paste False, False, False
End If
Next
End Sub
-
Welcome to the board. Please format your VBA code using code tags like this:
[vba]
' your code goes here
[/vba]
There is no Body.Select method. I think you are trying to copy and paste the body of an email into an Excel worksheet. If so, what you want to do is assign the Body property to a String variable, then set an Excel worksheet range to that variable. Ex:
[vba]
' declare variable to hold email body
Dim emailbody As String
' ... skip ahead ...
If item.Subject Like "Test outlook-Excel" Then
'item.Display
emailbody = item.Body
' .... skip ahead ...
xlApp.Worksheets(1).Range("a1").value = emailbody
[/vba]
-
Hi JP,
thank you very much for your reply.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules