NYFashionToGo
Technical User
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
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