Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy message/s within Outlook

Status
Not open for further replies.

i12hvfun

Programmer
Jul 26, 2002
20
SG
Hi All,
can anyone assist me on how to code moving or copying the message in Outlook between folder, eg, from 'Inbox' to 'Seen'.
Thanks.
 
i12hvfun

can anyone assist me on how to code moving or copying the message in Outlook between folder, eg, from 'Inbox' to 'Seen'.

The trick is to determine the folder ID number of your "Seen" folder, once you have determined that (Typically the folder ID number is in order of creation, for example I just created a folder called "seen" and determined that the folder was the 12th folder to be created) , that following will do it for you, it will move all Read messages to the folder number 12.
Code:
Local oOutlookObject,olNameSpace
#Define olFolderInBox 6
oOutlookObject = Createobject("Outlook.Application")
olNameSpace = oOutlookObject.GetNameSpace("MAPI")
oItems= olNameSpace.GetDefaultFolder(olFolderInBox).Items
For Each loItem In oItems
    If !loItem.unRead 
            loitem.Move(olNameSpace.Folders(1).Folders(12))
    Endif
Next

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks Mike.
Can I reference the folder by it's name instead of the folder number? That might be instances where this user's folder is 12th but 13th for another.
 
Can I reference the folder by it's name instead of the folder number? That might be instances where this user's folder is 12th but 13th for another.

No, you need the folder index number, which in fact the order they were created , so you need to discover the folder index number. Here is an example:

Code:
Local oOutlookObject,olNameSpace
#Define olFolderInBox 6
oOutlookObject = Createobject("Outlook.Application")
olNameSpace = oOutlookObject.GetNameSpace("MAPI")
oFolders= olNameSpace.folders(1).folders
i = 1
FOR EACH oFolder IN oFolders
  IF  olNameSpace.folders(1).folders(i).name = "Seen"
    nFoldernumber = i
    exit
  ENDIF
  i = i + 1
endfor
oItems= olNameSpace.GetDefaultFolder(olFolderInBox).Items
For Each loItem In oItems
    If !loItem.unRead 
            loitem.Move(olNameSpace.Folders(1).Folders(nFolderNumber))
    Endif
Next

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top