×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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 --> VBScript

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 

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

(OP)
Solution:

CODE --> VBScript

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close