Macro for Outlook 2007

zabiullakhan

Active Member
Joined
Aug 30, 2010
Messages
310
I have this code which gives me only the count of my inbox email.. how can i modify to count my achive forlder or sent items or personal folders with specific name(ex: "office","Personal","Bank") etc..

Code:
Sub CountInbox()
Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
MsgBox Fldr.Items.Count
Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
Please help.. :banghead:
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

zabiullakhan

Active Member
Joined
Aug 30, 2010
Messages
310
Which path do i need to pass to this function as i dont know from where do i take the path of my archive folder.. Please help

Code:
Function GetFolder(FolderPath)
  ' folder path needs to be something like
  '   "Public Folders\All Public Folders\Company\Sales"
  Dim aFolders
  Dim fldr
  Dim i
  Dim objNS
  On Error Resume Next
  strFolderPath = Replace(FolderPath, "/", "\")
  aFolders = Split(FolderPath, "\")
  'get the Outlook objects
  ' use intrinsic Application object in form script
  Set objNS = Application.GetNamespace("MAPI")
  'set the root folder
  Set fldr = objNS.Folders(aFolders(0))
  'loop through the array to get the subfolder
  'loop is skipped when there is only one element in the array
  For i = 1 To UBound(aFolders)
    Set fldr = fldr.Folders(aFolders(i))
    'check for errors
    If Err <> 0 Then Exit Function
  Next
  Set GetFolder = fldr
  ' dereference objects
  Set objNS = Nothing
End Function
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
In the link I gave you its sats:

The path argument needs to be in quotation marks and exactly match the folder hierarchy that the user sees in the Folder List. An easy way to see the path string is to display the Web toolbar (View | Toolbars) and look in its Address box. Omit the "Outlook:" prefix if you copy the path string for use with GetFolder().

So try that.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,984
Messages
5,526,058
Members
409,682
Latest member
HisHailo

This Week's Hot Topics

Top