?
Solved

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

Posted on 2003-03-10
5
Medium Priority
?
226 Views
Last Modified: 2010-04-07
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
Comment
Question by:jlalande
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Flash828
ID: 8110458
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
 
LVL 3

Accepted Solution

by:
Flash828 earned 750 total points
ID: 8110465
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
 

Author Comment

by:jlalande
ID: 8114641
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
 

Author Comment

by:jlalande
ID: 8114733
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
 

Author Comment

by:jlalande
ID: 8114742
Thanks for your help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question