Hello Chandoo,
I had gone through ur Webiste, it's awesome, i have a quick quesion: I want to transfer My Inbox mails data i.e body to Excel and same should happen automatically i.e time need to be set. is that possible in VBA, i have done VBA and same is pasted down but
I am unable to set time and if want only particular person mail need to be transfered to excel, how to do that
VBA Code:
[pre]
[/pre]
I had gone through ur Webiste, it's awesome, i have a quick quesion: I want to transfer My Inbox mails data i.e body to Excel and same should happen automatically i.e time need to be set. is that possible in VBA, i have done VBA and same is pasted down but
I am unable to set time and if want only particular person mail need to be transfered to excel, how to do that
VBA Code:
[pre]
Code:
Sub CopyToExcel()
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim olItem As Outlook.MailItem
Dim r As Long
Dim bXStarted As Boolean
Const strPath As String = "C:Documents and Settingssri.guruDesktopTest.xlsx" 'the path of the workbook
If Application.ActiveExplorer.Selection.Count = 0 Then
MsgBox "No Items selected!", vbCritical, "Error"
Exit Sub
End If
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Application.StatusBar = "Please wait while Excel source is opened ... "
Set xlApp = CreateObject("Excel.Application")
bXStarted = True
End If
On Error GoTo 0
'Open the workbook to input the data
Set xlWB = xlApp.Workbooks.Open(strPath)
Set xlSheet = xlWB.Sheets("Sheet1")
'Process each selected record
For Each olItem In Application.ActiveExplorer.Selection
'Find the next empty line of the worksheet
r = xlSheet.Range("A" & xlSheet.Rows.Count).End(xlUp).Row
r = r + 1
xlSheet.Cells(r, "A") = olItem.Subject
xlSheet.Cells(r, "B") = olItem.sendername
xlSheet.Cells(r, "C") = olItem.To
xlSheet.Cells(r, "D") = olItem.ReceivedTime
xlSheet.Cells(r, "E") = olItem.Attachments.Count
xlSheet.Cells(r, "F") = olItem.Size
xlSheet.Cells(r, "G") = olItem.Body
xlSheet.Cells(r, "h") = olItem.senderemailaddress
xlWB.Save
End Sub
Next olItem
xlWB.Close SaveChanges:=True
If bXStarted Then
xlApp.Quit
End If
Set xlApp = Nothing
Set xlWB = Nothing
Set xlSheet = Nothing
Set olItem = Nothing
End Sub