A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

how to find outlook folder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 28th 07, 03:34 AM posted to microsoft.public.outlook.program_vba
ed
external usenet poster
 
Posts: 114
Default how to find outlook folder

I'm trying to use vba to write a macro that will goto the undeliverables
folder and open each item in it and search for a string.

I can't seem to connect to the undeliverables folder.
Here is a snippet of the code I am using:
---------------
Sub SearchUndelsFolder()
' Dim objRsts As Results
'establish two variables
Dim n As Integer
n = 0
Dim address As String

'create output file system object
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\FailedAddresses.txt", True)

'call the Outlook application MAPI interface
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")

'Address the Undeliverables folder
Set myFolder = myNamespace.GetFolder("undeliverables")

'count entries in undeliverables folder
Set filecount = myFolder.Items.Count

'for each message body in the MAPI undeliverables subdirectiry
'address the message body of the nth entry in MyFolder

------------------
the code is failing at the MAPI call. Am I missing somethiing? The macro
crashed when it gets to the MAPI call.
I get this error message:
runtime error 1163395067 (baa80005)
the progrrm for the attachment may not have been installed lproperly or may
have been moved or deleted. reinstall the hprogram in hhich the attachment
was created.

I don't think I'm calling access to the undeliverables folder properly, but
can't figure out the proper call. Can you help?
Ed
Ads
  #2  
Old April 30th 07, 09:44 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default how to find outlook folder

There is no GetFolder method! There are three ways to get a MAPIFolder object:

- use the Namespace.GetFolderFromID method if you know the ID of the folder
- "walk" the Namespace.Folders collection until you get the folder you want
(e.g. myFolder =
myNamespace.Folders("Inbox").Folders("SubFolder"). Folders("AnotherSubFolder")
- use the function below if you know the path to the folder

'************************************************* *****************************
'Custom procedu OpenMAPIFolder(ByVal strPath)
'Purpose: Return a MAPIFolder from Path argument
'Returns: MAPIFolder object
'************************************************* *****************************
Function OpenMAPIFolder(ByVal strPath) As Outlook.MAPIFolder
On Error Resume Next

Dim objFldr As MAPIFolder
Dim strDir As String
Dim strName As String
Dim i As Integer
If Left(strPath, Len("\")) = "\" Then
strPath = Mid(strPath, Len("\") + 1)
Else
Set objFldr = Application.ActiveExplorer.CurrentFolder
End If
While strPath ""
i = InStr(strPath, "\")
If i Then
strDir = Left(strPath, i - 1)
strPath = Mid(strPath, i + Len("\"))
Else
strDir = strPath
strPath = ""
End If
If objFldr Is Nothing Then
Set objFldr = Application.GetNamespace("MAPI").Folders(strDir)
On Error GoTo 0
Else
Set objFldr = objFldr.Folders(strDir)
End If
Wend
Set OpenMAPIFolder = objFldr
End Function

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Ed" wrote:

I'm trying to use vba to write a macro that will goto the undeliverables
folder and open each item in it and search for a string.

I can't seem to connect to the undeliverables folder.
Here is a snippet of the code I am using:
---------------
Sub SearchUndelsFolder()
' Dim objRsts As Results
'establish two variables
Dim n As Integer
n = 0
Dim address As String

'create output file system object
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\FailedAddresses.txt", True)

'call the Outlook application MAPI interface
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")

'Address the Undeliverables folder
Set myFolder = myNamespace.GetFolder("undeliverables")

'count entries in undeliverables folder
Set filecount = myFolder.Items.Count

'for each message body in the MAPI undeliverables subdirectiry
'address the message body of the nth entry in MyFolder

------------------
the code is failing at the MAPI call. Am I missing somethiing? The macro
crashed when it gets to the MAPI call.
I get this error message:
runtime error 1163395067 (baa80005)
the progrrm for the attachment may not have been installed lproperly or may
have been moved or deleted. reinstall the hprogram in hhich the attachment
was created.

I don't think I'm calling access to the undeliverables folder properly, but
can't figure out the proper call. Can you help?
Ed

  #3  
Old June 21st 07, 07:59 PM posted to microsoft.public.outlook.program_vba
DENNIS BROWN
external usenet poster
 
Posts: 51
Default how to find outlook folder

Great!

--

Thanks,
Dennis
"Eric Legault [MVP - Outlook]" wrote in message ...
There is no GetFolder method! There are three ways to get a MAPIFolder object:

- use the Namespace.GetFolderFromID method if you know the ID of the folder
- "walk" the Namespace.Folders collection until you get the folder you want
(e.g. myFolder =
myNamespace.Folders("Inbox").Folders("SubFolder"). Folders("AnotherSubFolder")
- use the function below if you know the path to the folder

'************************************************* *****************************
'Custom procedu OpenMAPIFolder(ByVal strPath)
'Purpose: Return a MAPIFolder from Path argument
'Returns: MAPIFolder object
'************************************************* *****************************
Function OpenMAPIFolder(ByVal strPath) As Outlook.MAPIFolder
On Error Resume Next

Dim objFldr As MAPIFolder
Dim strDir As String
Dim strName As String
Dim i As Integer
If Left(strPath, Len("\")) = "\" Then
strPath = Mid(strPath, Len("\") + 1)
Else
Set objFldr = Application.ActiveExplorer.CurrentFolder
End If
While strPath ""
i = InStr(strPath, "\")
If i Then
strDir = Left(strPath, i - 1)
strPath = Mid(strPath, i + Len("\"))
Else
strDir = strPath
strPath = ""
End If
If objFldr Is Nothing Then
Set objFldr = Application.GetNamespace("MAPI").Folders(strDir)
On Error GoTo 0
Else
Set objFldr = objFldr.Folders(strDir)
End If
Wend
Set OpenMAPIFolder = objFldr
End Function

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Ed" wrote:

I'm trying to use vba to write a macro that will goto the undeliverables
folder and open each item in it and search for a string.

I can't seem to connect to the undeliverables folder.
Here is a snippet of the code I am using:
---------------
Sub SearchUndelsFolder()
' Dim objRsts As Results
'establish two variables
Dim n As Integer
n = 0
Dim address As String

'create output file system object
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\FailedAddresses.txt", True)

'call the Outlook application MAPI interface
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")

'Address the Undeliverables folder
Set myFolder = myNamespace.GetFolder("undeliverables")

'count entries in undeliverables folder
Set filecount = myFolder.Items.Count

'for each message body in the MAPI undeliverables subdirectiry
'address the message body of the nth entry in MyFolder

------------------
the code is failing at the MAPI call. Am I missing somethiing? The macro
crashed when it gets to the MAPI call.
I get this error message:
runtime error 1163395067 (baa80005)
the progrrm for the attachment may not have been installed lproperly or may
have been moved or deleted. reinstall the hprogram in hhich the attachment
was created.

I don't think I'm calling access to the undeliverables folder properly, but
can't figure out the proper call. Can you help?
Ed

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003 Find in Public Folder Contacts Matthew Anderson Outlook - Using Contacts 2 October 1st 06 12:46 AM
MS Outlook 2002 can not find default e-mail folder yakarobed Outlook - Installation 1 September 18th 06 04:26 AM
Outlook Cannot find default file folder Mike Rignall Outlook - Installation 1 April 16th 06 07:20 PM
Outlook cannot find contact folder Glyn Outlook - Using Contacts 1 April 4th 06 07:07 PM
How do I find and delete an Outlook personal mail folder? Terry Outlook - Installation 2 April 2nd 06 07:10 AM


All times are GMT +1. The time now is 10:42 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.