Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Extract Email From Outlook to Excel, Subfolders

Status
Not open for further replies.

NYFashionToGo

Technical User
Jan 16, 2007
76
0
0
US
Goodmorning,

I have some code posted below that I use to answer some questions that I typically get.

In Outlook I have a folder named NYF Questions, I have some subfolders added to this folder. How would I alter the code to extract Email from one of those subfolders....

I have now
Set objTarget = objFolder.Folders("NYF Questions")

Set objTarget = objFolder.Folders("NYF Questions/WebsiteQuestions")

I cant seem toget this to work...

Any info would be helpful. Thank you in advance..




Sub Step1GetOutlookItemsEmail()
On Error GoTo GetOutlookItems_Error
'Outlook
Dim objOutlook As Object
Dim objFolder As Object
Dim objTarget As Object
Dim objItem As Object
'Excel
Dim wksOutput As Worksheet
Dim rngToSort As Range
Dim lngRow As Long

Sheets("NYFeMail").Select
Cells.Select
Selection.ClearContents
Range("A1").Select

Set wksOutput = ActiveSheet
'Headers
lngRow = 1
wksOutput.Cells(lngRow, 17) = "SenderName"
wksOutput.Cells(lngRow, 18) = "Subject"
wksOutput.Cells(lngRow, 19) = "SentOn"
wksOutput.Cells(lngRow, 20) = "Body"
lngRow = 2




'get NYF Email from outlook
Set objOutlook = GetObject(, "Outlook.Application")
'This would be a public folder
Set objFolder = objOutlook.Session.Folders("Personal Folders")







'XXXXXXX How to Extract from a subfolder of the folder
'Below





Set objTarget = objFolder.Folders("NYF Questions")
For Each objItem In objTarget.Items
If objItem.Class = 43 Then 'olMail
With objItem
wksOutput.Cells(lngRow, 17) = .SenderName
wksOutput.Cells(lngRow, 18) = .Subject
wksOutput.Cells(lngRow, 19) = .SentOn
wksOutput.Cells(lngRow, 20) = .Body
End With
lngRow = lngRow + 1
End If
Next objItem





Clean_Up:
Set wksOutput = Nothing
Set objItem = Nothing
Set objTarget = Nothing
Set objFolder = Nothing
Set objOutlook = Nothing
Exit Sub
GetOutlookItems_Error:
Debug.Print Err.Number, Err.Description
Resume Clean_Up
End Sub
 
Perhaps this ?
Set objTarget = objFolder.Folders("NYF Questions").Folders("WebsiteQuestions")

Or this ?
Set objTarget = objFolder.Folders("NYF Questions")
Set objTarget = objTarget.Folders("WebsiteQuestions")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top