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

Hardcoding an Outlook 2003 folder name in a Macro?



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old May 30th 06, 02:43 AM posted to microsoft.public.outlook.program_vba
James
external usenet poster
 
Posts: 90
Default Hardcoding an Outlook 2003 folder name in a Macro?

I'm trying to create a macro that searches a folder called "electronics"
for a string in the subject "TV" and if it is a match, then moves the msg to
the inbox. I cannot get the following code to work. The line
Set olStartFolder = olSession.Folders("electronics")
isn't correct so thecode bombs. How do i do it? Thanks. James


Dim strSearchString As String
Dim lCountOfFound As Long

Sub WalkFolders()

Dim olApp As Outlook.Application
Dim olSession As Outlook.NameSpace
Dim olStartFolder As Outlook.MAPIFolder
Dim strPrompt As String

'Initialize count of folders searched
lCountOfFound = 0

' Get a reference to the Outlook application and session.
Set olApp = Application
Set olSession = olApp.GetNamespace("MAPI")

' Allow the user to input the search string.
strPrompt = "Enter the search string to be found in the subject:"
strSearchString = InputBox(strPrompt)

If strSearchString "" Then

' Allow the user to pick the folder in which to start the search.
' Set olStartFolder = olSession.PickFolder

Set olStartFolder = olSession.Folders("electronics")


' Check to make sure user didn't cancel PickFolder dialog.
If Not (olStartFolder Is Nothing) Then
' Start the search process.
ProcessFolder olStartFolder
MsgBox CStr(lCountOfFound) & " messages were found."
End If

End If

End Sub

Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder)

Dim i As Long
Dim olNewFolder As Outlook.MAPIFolder
' late bind this object variable, since it could be various item types
Dim olTempItem As Object

' Loop through the items in the current folder.
' Looping through backwards in case items are to be deleted,
' as this is the proper way to delete items in a collection.
For i = CurrentFolder.Items.Count To 1 Step -1

Set olTempItem = CurrentFolder.Items(i)

' Check to see if a match is found
If InStr(1, olTempItem.Subject, strSearchString, 0) 0 Then

' The following are examples of what you can do:
' 1. To notify that message was found:
' MsgBox "Found message with subject: " & olTempItem.Subject
'
' 2. To delete the item:
' olTempItem.Delete
'
' 3. To move the item:
' NOTE: You need to first define olDestFolder
' olTempItem.Move olDestFolder
'
lCountOfFound = lCountOfFound + 1

End If

Next

' Loop through and search each subfolder of the current folder.
For Each olNewFolder In CurrentFolder.Folders

If olNewFolder.Name "Deleted Items" Then
ProcessFolder olNewFolder
End If

Next

End Sub




 




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
Calendar folder missing from folder list in outlook 2003 Bill B Outlook - Calandaring 11 July 7th 06 04:44 PM
Importing Outlook Alias into an Excel 2003 macro fidgitthedigit Outlook - General Queries 2 May 30th 06 02:11 PM
Outlook 2003: Macro field is empty .. vbaproject.otm not recognized Kemal Balioglu Outlook and VBA 2 May 26th 06 05:45 PM
view folder size in outlook using a macro john mcmichael Outlook and VBA 0 May 4th 06 04:07 PM
Contacts folder in Outlook 2003 Jos Sall Outlook - Using Contacts 3 February 21st 06 06:58 AM


All times are GMT +1. The time now is 05:56 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.