• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

How do I move an item from one folder to another in VBScript?

In a previous question, I asked and learned how to get a reference to the currently selected email.  I've done some work with it and now I'd like to move it to another folder.
Can someone explain this process to me?
Thanks
0
jlalande
Asked:
jlalande
  • 3
  • 2
1 Solution
 
Flash828Commented:
This code is from an MSDN page:

URL: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol10/html/olmthMove.asp

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Personal Mail")
Set myItem = myItems.Find("[SenderName] = 'Mike Nash'")
While TypeName(myItem) <> "Nothing"
    myItem.Move myDestFolder
    Set myItem = myItems.FindNext
Wend
If you use VBScript, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.

Set myNameSpace = Application.GetNameSpace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(6)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Personal Mail")
Set myItem = myItems.Find("[SenderName] = 'Mike Nash'")
While TypeName(myItem) <> "Nothing"
    myItem.Move myDestFolder
    Set myItem = myItems.FindNext
Wend
0
 
Flash828Commented:
Sorry highlighted too much.. it should be this:

This code is from an MSDN page:

URL: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol10/html/olmthMove.asp

Set myNameSpace = Application.GetNameSpace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(6)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Personal Mail")
Set myItem = myItems.Find("[SenderName] = 'Mike Nash'")
While TypeName(myItem) <> "Nothing"
   myItem.Move myDestFolder
   Set myItem = myItems.FindNext
Wend
0
 
jlalandeAuthor Commented:
This works fine if "Personal Mail" is a subfolder of "Inbox".  The folder I would like to move my message is to a folder at the same level as "Inbox".
0
 
jlalandeAuthor Commented:
OK.
I figured out how to get my folder.  Instead of

Set myDestFolder = myInbox.Folders("Scratch")

I did

Set myDestFolder = myInbox.Parent.Folders("Scratch")

0
 
jlalandeAuthor Commented:
Thanks for your help.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now