VBA code to MOVE and COPY msgs?

  • Thread starter Thread starter StargateFanFromWork
  • Start date Start date
S

StargateFanFromWork

I use the MOVE and COPY TO FOLDER buttons a lot. So much so that it would
save me a great deal of time to just have two buttons on my toolbar with
macros to automate this.

Does anyone have the line of VBA script code to do each?

Thank you; I really appreciate the help. :oD
 
Sue Mosher said:
What exactly is it that you want to automate that the existing button
doesn't do for you?

I'm sorry, I chuckled when I read this. Well, as always, when we're looking
for a shortcut, that's exactly what it means - a shortcut <g>. I'd really
love to save keystrokes. I move/copy to so many different folders all the
time but there are two that I move or copy to a lot. I'd like to automate
those. Again, rather than have many mouse-clicks, whether or not there's a
toolbar option available already, I'd like to do up a macro and have the
code available by _one_ mouse click for those two folders, etc., I deal with
the most.

Thank you.
 
The MoveItem procedure below is a generic subroutine for moving a currently selected or open single item to the folder whose path is specified as the argument for the procedure:

Sub MoveItem(strFolderPath As String)
On Error Resume Next
Set objItem = GetCurrentItem()
' GetCurrentItem function from
' http://www.outlookcode.com/codedetail.aspx?id=50
Set objFolder = GetFolder(strFolderPath)
' GetFolder function from
' http://www.outlookcode.com/d/code/getfolder.htm
objItem.Move objFolder
Set objFolder = Nothing
Set objItem = Nothing
End Sub

You will need to include the GetFolder() and GetCurrentItem() functions in your VBA project. These are basic building block functions you can reuse.

You can then write as many macros as you want that call the MoveItem() function with different folder path arguments, e.g.:

Sub MoveToInboxFolder1
Call MoveItem("Personal Folders\Inbox\Folder1")
End Sub

I'll leave it to you to adapt to copying instead of moving. To copy an item to a folder, you create a copy, then move the copy:

Set objCopy = objItem.Copy
objCopy.Move objFolder

I'll also leave it to you to modify the basic procedure to handle more than one selected item. (HINT: Don't use GetCurrentItem(). Instead, incorporate the techniques used by GetCurrentItem() into your code.)
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
The MoveItem procedure below is a generic subroutine for moving a currently selected or open single item to the folder whose path is specified as the argument for the procedure:

Sub MoveItem(strFolderPath As String)
On Error Resume Next
Set objItem = GetCurrentItem()
' GetCurrentItem function from
' http://www.outlookcode.com/codedetail.aspx?id=50
Set objFolder = GetFolder(strFolderPath)
' GetFolder function from
' http://www.outlookcode.com/d/code/getfolder.htm
objItem.Move objFolder
Set objFolder = Nothing
Set objItem = Nothing
End Sub

You will need to include the GetFolder() and GetCurrentItem() functions in your VBA project. These are basic building block functions you can reuse.

Perfect, thank you! That sounds like it's what I need.
You can then write as many macros as you want that call the MoveItem() function with different folder path arguments, e.g.:
Kewl!

Sub MoveToInboxFolder1
Call MoveItem("Personal Folders\Inbox\Folder1")
End Sub

I'll leave it to you to adapt to copying instead of moving. To copy an item to a folder, you create a copy, then move the copy:

Set objCopy = objItem.Copy
objCopy.Move objFolder

I'll also leave it to you to modify the basic procedure to handle more than one selected item. (HINT: Don't use GetCurrentItem(). Instead, incorporate the techniques used by GetCurrentItem() into your code.)

Thank you! I'm going to have fun with this <g>.
 
Sue,
may I add a question ?
I would like to copy an Email to the Task Folder and then
change some properties of that new TaskItem.
I managed to copy the mailItem to the TaskFolder, but how
do I get hold of that item in order to change the
properties ?

Thanks in advance for any hint
Frank

-----Original Message-----
The MoveItem procedure below is a generic subroutine for
moving a currently selected or open single item to the
folder whose path is specified as the argument for the
procedure:
Sub MoveItem(strFolderPath As String)
On Error Resume Next
Set objItem = GetCurrentItem()
' GetCurrentItem function from
' http://www.outlookcode.com/codedetail.aspx?id=50
Set objFolder = GetFolder(strFolderPath)
' GetFolder function from
' http://www.outlookcode.com/d/code/getfolder.htm
objItem.Move objFolder
Set objFolder = Nothing
Set objItem = Nothing
End Sub

You will need to include the GetFolder() and
GetCurrentItem() functions in your VBA project. These are
basic building block functions you can reuse.
You can then write as many macros as you want that call
the MoveItem() function with different folder path
arguments, e.g.:
Sub MoveToInboxFolder1
Call MoveItem("Personal Folders\Inbox\Folder1")
End Sub

I'll leave it to you to adapt to copying instead of
moving. To copy an item to a folder, you create a copy,
then move the copy:
Set objCopy = objItem.Copy
objCopy.Move objFolder

I'll also leave it to you to modify the basic procedure
to handle more than one selected item. (HINT: Don't use
GetCurrentItem(). Instead, incorporate the techniques used
by GetCurrentItem() into your code.)
 
Moving an email message to another folder programmatically doesn't
necessarily create a new item of the default type for that folder. Instead,
you should create a new TaskItem and then set its properties to include
whatever information you wanted to pass along from the original message.

FYI, it's bad form to insert an unrelated question into an existing
discussion. Instead, start your own discussion with a new topic.
 
Moving an email message to another folder programmatically doesn't
necessarily create a new item of the default type for that folder. Instead,
you should create a new TaskItem and then set its properties to include
whatever information you wanted to pass along from the original message.

I do this all the time with no problem. Since I don't have a PDA or
any type of electronic organizer, and since I have cable internet at
home so that my computer is on 24/7, I'll often send myself an email
to work to remind me to do something.

When I get to work, I'll move that email message to either the TASKS
folder or the CALENDAR folder and then edit for the date/time for that
reminder to come up (I use the Calendar for repeating items and Tasks
for one-time items).

Since I use the MOVE feature rather than COPY, I don't even have to go
back and delete the individual email as it gets converted right away.

Just something I stumbled upon about a year ago when I accidentally
moved an email message to the STICKIE notes folder instead of my
target folder and got a bit of a shock when I saw my email get
converted to a stickie note! <g> I then tried it on all the other
folders and was very delighted with this neat feature.

I'm using O2K, btw, in case that makes a difference.
 
Back
Top