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

Macro for Moving and Copying Mail



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 15th 08, 01:23 AM posted to microsoft.public.outlook.program_vba
paul
external usenet poster
 
Posts: 197
Default Macro for Moving and Copying Mail

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

Ads
  #2  
Old January 15th 08, 02:00 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Macro for Moving and Copying Mail

If it's a subfolder of the Inbox, then it's a member of the Inbox's Folders collection:

Set objFolder = objInbox.Folders("Miscellaneous")

To get a non-default folder, you need to walk the folder hierarchy using the Folders collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm and, especially for public folders, http://www.outlookcode.com/codedetail.aspx?id=1164

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


"Paul" wrote in message ...
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

  #3  
Old January 15th 08, 11:54 PM posted to microsoft.public.outlook.program_vba
paul
external usenet poster
 
Posts: 197
Default Macro for Moving and Copying Mail

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 a

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.




"Sue Mosher [MVP-Outlook]" wrote:

If it's a subfolder of the Inbox, then it's a member of the Inbox's Folders collection:

Set objFolder = objInbox.Folders("Miscellaneous")

To get a non-default folder, you need to walk the folder hierarchy using the Folders collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm and, especially for public folders, http://www.outlookcode.com/codedetail.aspx?id=1164

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


"Paul" wrote in message ...
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


  #4  
Old January 16th 08, 12:44 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Macro for Moving and Copying Mail

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


"Paul" wrote in message ...
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 a

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.




"Sue Mosher [MVP-Outlook]" wrote:

If it's a subfolder of the Inbox, then it's a member of the Inbox's Folders collection:

Set objFolder = objInbox.Folders("Miscellaneous")

To get a non-default folder, you need to walk the folder hierarchy using the Folders collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm and, especially for public folders, http://www.outlookcode.com/codedetail.aspx?id=1164



"Paul" wrote in message ...
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


 




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
Copying/Moving problems mjbyyz Outlook Express 2 November 15th 07 10:33 PM
Copying/Moving/Saving an Embedded/Attached Message to a Mail Folder B Outlook and VBA 1 August 21st 07 08:46 PM
copying e-mail addresses (display names) from body of e-mail jpampinella Outlook - Using Contacts 2 February 26th 07 09:40 PM
Rules for moving outside mails to specific folder (Macro) Moshico Outlook and VBA 1 January 22nd 07 03:03 PM
Macro for moving emails to a particular folder Gr6au Outlook and VBA 1 October 2nd 06 06:34 AM


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