Macro for Moving and Copying Mail

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

Paul

Hello,

I need to be able to select a message and have a copy go to one folder and
the original be moved to a second folder. One of these folders is in the
tree under the inbox the other is not. I found the following example that
someone else posted. I cannot get it to recognize the subfolder (HELP ME
HERE) spot. I have tried every formatting option I can think of. Assuming
the folder name is Miscellaneous, what should it look like in that variable
definition?

Second, how can I add a second part to copy it to the folder which is not in
the inbox tree?

Thank you so very very much!!!!

Sub HVR_Const()

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(HELP ME HERE)
'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
 
Sue,

Your help was great, but I cannot make it work. I am sure it is a
formatting issue. The folder I want to get to are:

Inbox\Projects\City of Peoria\193648 - Happy Valley Road\Construction

and

Public Folder\All Public Folder\Phoenix\Transportation\Job\193648 - Happy
Valley

I am not even sure I have the correct divider (/ vs \) or if the space is
creating a problem....

This should not be this hard
Thanks for being there for all of us.
 
The GetFolder() function at the URL I suggested doesn't care whether you use a / or \. It can handle either (since some of us forget which is used when). Spaces are expected and normal.

We cannot look over your shoulder, however, and see what's going wrong. You have to at least show the relevant code snippet and tell us what unexpected behavior you're seeing. Ideally, you'd also step through the code in the debugger to see what code statements do and do not execute.

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