Results 1 to 2 of 2

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

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2015
    Posts
    3

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

    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

  2. #2

    Thread Starter
    New Member
    Join Date
    Dec 2015
    Posts
    3

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

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width