Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / May 2008

Tip: Looking for answers? Try searching our database.

Folder Identification

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 22 May 2008 17:44 GMT
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
Sue Mosher [MVP-Outlook] - 22 May 2008 17:57 GMT
What errors? With what code? Are you referring to Outlook folders or system folders?

Signature

Sue Mosher, Outlook MVP
  Author of Microsoft Outlook 2007 Programming:
    Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54

>I am trying to create a button that will
>
[quoted text clipped - 9 lines]
>
> Frustrated
Dmitry Streblechenko - 22 May 2008 18:00 GMT
What *exactly* are you having problems with? What are the relevant snippets
of your code?

Signature

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

>I am trying to create a button that will
>
[quoted text clipped - 11 lines]
>
> Frustrated
Paul - 22 May 2008 18:57 GMT
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

> What *exactly* are you having problems with? What are the relevant snippets
> of your code?
[quoted text clipped - 14 lines]
> >
> > Frustrated
Dmitry Streblechenko - 22 May 2008 19:29 GMT
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")

Signature

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

> This is the starter code:
>
[quoted text clipped - 48 lines]
>> >
>> > Frustrated
Paul - 22 May 2008 22:31 GMT
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

> Mailbox\Inbox\Projects\City 1\Project 1:
> set Folder =
[quoted text clipped - 58 lines]
> >> >
> >> > Frustrated
Dmitry Streblechenko - 23 May 2008 06:13 GMT
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

Signature

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

> Dmitry,
>
[quoted text clipped - 112 lines]
>> >> >
>> >> > Frustrated
Paul - 23 May 2008 15:31 GMT
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

> 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
[quoted text clipped - 119 lines]
> >> >> >
> >> >> > Frustrated
Dmitry Streblechenko - 23 May 2008 17:58 GMT
Why are you calling Copy twice?

Signature

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
[quoted text clipped - 180 lines]
>> >> >> >
>> >> >> > Frustrated
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.