Folder Identification

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I am trying to create a button that will

1) copy an e-mail to a directory
2) move the same e-mail to different directory

basically I need to file it in two places. Other ways of managing this are
not an option.

I have gotten a lot of item on ways to do this, but I am always getting
errors on the folder name. These are both local and shared folders. Is
there an easy way of creating the folder path for insertion into the VBA code

Frustrated
 
What errors? With what code? Are you referring to Outlook folders or system folders?
 
What *exactly* are you having problems with? What are the relevant snippets
of your code?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
This is the starter code:

Sub Paul()
On Error Resume Next

Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder = objInbox.Parent.Folders("Project 1")
'Assume this is a mail folder

If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If

If Application.ActiveExplorer.Selection.Count = 0 Then
'Require that this procedure be called only when a message is selected
Exit Sub
End If

These are the directories that I want to 'hit'

Local Directory: Mailbox\Inbox\Projects\City 1\Project 1
Global: All Public Folders\ABC\State\Transportation\Jobs\Project 1

Thanks
 
Mailbox\Inbox\Projects\City 1\Project 1:
set Folder =
objNS.GetDefaultFolder(olFolderInbox).Folders("Projects").Folders("City
1").Folders("Project 1")

All Public Folders\ABC\State\Transportation\Jobs\Project 1:
set Folder =
objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("ABC").Folders("State").Folders("Transportation").Folders("Jobs").Folders("Project
1")

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Dmitry,

Thank you for you help so far, I am sure that we are close. This is what I
have:

Sub Paul()
On Error Resume Next

Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem

Set objNS = Application.GetNamespace("MAPI")
Set objFolder =
objNS.GetDefaultFolder(olFolderInbox).Folders("Projects").Folders("City of
Peoria").Folders("193648 - Happy Valley Road")

'Assume this is a mail folder

If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If

If Application.ActiveExplorer.Selection.Count = 0 Then
'Require that this procedure be called only when a message is selected
Exit Sub
End If

For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.Copy objFolder
End If
End If
Next

Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub


What it does is it placees a copy in the inbox. There is nothing obvious to
me, but maybe you or someone else could help determine why it is not going to
Set Folder.

Thanks
 
MailItem.Copy does not take any parameters (folder or anything else). It
simply creates and returns the new item created in (you guessed it) the
Inbox folder:

set objNewItem = objItem.Copy
objNewItem.MoveTo objFolder

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Thanks for the help...I am still stumped and really wish Outlook had a
recorder. I understand your note and made the following changes of adding
your statements to the if loop. What I get now are two copies in my
in-basket....if you could help me with the missing link it would be great.
And my next step is to take this same message and move it to the public
folder down below. So in short I want to take the message in my in-box and
have it placed into moved/copied into two folders and not be in my inbox
(copy base message to folder 1, move message from inbox to folder 2)

Thanks in advance

Sub Paul()
On Error Resume Next

Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem

Set objNS = Application.GetNamespace("MAPI")
Set objFolder =
objNS.GetDefaultFolder(olFolderInbox).Folders("Projects").Folders("City of
Peoria").Folders("193648 - Happy Valley Road")


'Assume this is a mail folder

If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If

If Application.ActiveExplorer.Selection.Count = 0 Then
'Require that this procedure be called only when a message is selected
Exit Sub
End If

For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.Copy
Set objNewItem = objItem.Copy
objNewItem.MoveTo objFolder
End If
End If
Next

Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
 
Back
Top