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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to get most recent subject headings from specific (not inbox) folder

Status
Not open for further replies.

Don Child

Programmer
Apr 4, 2003
65
US
Hi,

I'm confused about how to get emails from a specific folder. Almost all of the examples on the web, are assuming that you're getting data from either inbox, or a subfolder of inbox.

The folder I'm trying to obtain the subject headings from, is called

ThisSpecificFolder


, in this example. There are several other folders, also on the same parent level as inbox. But I'm interested only in this specific folder.


Code:
Dim objOutlook
Dim objNamespace
Dim colFolders
Dim objFldr
Dim objItms


Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colFolders = objNamespace.Folders


'// This doesn't seem to be accomplishing it,
'//  but I'm not sure what to do next.

Set objFldr = objNamespace.Folders("ThisSpecificFolder")
Set objItms = objFldr.Items
 
Solution:

Code:
Dim objOutlook
Dim TargetFolder_s
Dim objNamespace
Dim colFolders

TargetFolder_s = "ThisSpecificFolder"
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colFolders = objNamespace.Folders

RecurseFolders colFolders, TargetFolder_s



Set objOutlook = Nothing
Set objNamespace = Nothing
Set colFolders = Nothing


WScript.Quit



Sub RecurseFolders(objTheseFolders, TargetFolder_s)
Dim objItems
Dim objItem
Dim Subject_s
Dim var_s 
Dim FolderName_s
For Each ThisFolder In objTheseFolders
	FolderName_s = ThisFolder.Name
	If FolderName_s = "1_Responses_to_Me" Then
		WScript.Echo FolderName_s
		Set objItems = ThisFolder.Items
		
		For Each objItem In objItems
			Subject_s = objItem.Subject
			WScript.Echo Subject_s
		Next
	End If
	ReDim Preserve strPaths(i + 1)
	strPaths(i) = ThisFolder.FolderPath
	Set colFolders2 = ThisFolder.Folders
	i = i + 1
	RecurseFolders colFolders2, TargetFolder_s
Next

Set objItems = Nothing
Set colFolders2 = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top