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

Programmatically moving selected messages to network folder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 25th 08, 07:32 PM posted to microsoft.public.outlook.program_vba
Ken Warthen
external usenet poster
 
Posts: 12
Default Programmatically moving selected messages to network folder

I'm working with a company who would like to automate some of their Outlook
2007 processes. They maintain a project folder on a server with folders
containing every document and communication related to a given project. They
currently move Outlook email messages to the respective project folder by
dragging and dropping them from Outlook to an Explorer window. I've set up a
contextual menu so that when a message is selected and right clicked the user
can select an option from the pop up menu to move the selected message to a
projects folder.

My intent was to have a folder dialog box open where the user can select the
appropriate project's folder and then move the message from Outlook to the
selected folder. It appears the Outlook's .Move command will only allow you
to move a message to an Outlook folder. Any ideas on how I might proceed
from here?

TIA,

Ken
Ads
  #2  
Old August 25th 08, 09:31 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Programmatically moving selected messages to network folder

Have you looked at SaveAs?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Ken Warthen" wrote in message
...
I'm working with a company who would like to automate some of their
Outlook
2007 processes. They maintain a project folder on a server with folders
containing every document and communication related to a given project.
They
currently move Outlook email messages to the respective project folder by
dragging and dropping them from Outlook to an Explorer window. I've set
up a
contextual menu so that when a message is selected and right clicked the
user
can select an option from the pop up menu to move the selected message to
a
projects folder.

My intent was to have a folder dialog box open where the user can select
the
appropriate project's folder and then move the message from Outlook to the
selected folder. It appears the Outlook's .Move command will only allow
you
to move a message to an Outlook folder. Any ideas on how I might proceed
from here?

TIA,

Ken


  #3  
Old August 25th 08, 10:41 PM posted to microsoft.public.outlook.program_vba
Ken Warthen
external usenet poster
 
Posts: 12
Default Programmatically moving selected messages to network folder


Ken

I've been playing with SaveAs as you can see in my code below. When I check
the destination folder there is an object there but it's label is truncated,
there's no .msg extension, and no message icon, as you would get when
dragging and dropping messages directly into the folder. The explorer window
also shows the file type as "File", where the messages that were dragged and
dropped have a file type "Outlook Item".

Private Sub MoveToDSiProjectFolder()
On Error GoTo PROC_ERROR
Dim objNamespace As NameSpace
Dim objItem As MailItem
Dim objRecipient As Recipient
Dim strEntryID As String
Dim strSubject As String
Dim strSender As String
Dim strRecipient As String
Dim strDestinationFolder As String

strEntryID =
Application.ActiveExplorer.CommandBars.ActionContr ol.Parameter

If strEntryID "" Then
Set objNamespace = Application.GetNamespace("MAPI")
Set objItem = objNamespace.GetItemFromID(strEntryID)

With objItem
strSubject = .Subject
strSender = .SenderName
strRecipient = .ReceivedByName
End With
strDestinationFolder = "C:\Users\kwarthen\Desktop\Project
Related Mail\"
objItem.SaveAs strDestinationFolder & objItem, olMSG
End If

PROC_EXIT:
On Error GoTo 0
Set objRecipient = Nothing
Set objItem = Nothing
Set objNamespace = Nothing
Exit Sub
PROC_ERROR:
Call ShowError("modDSi", "MoveToDSiProjectFolder", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
Resume
End Sub





Ken

"Ken Slovak - [MVP - Outlook]" wrote:

Have you looked at SaveAs?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Ken Warthen" wrote in message
...
I'm working with a company who would like to automate some of their
Outlook
2007 processes. They maintain a project folder on a server with folders
containing every document and communication related to a given project.
They
currently move Outlook email messages to the respective project folder by
dragging and dropping them from Outlook to an Explorer window. I've set
up a
contextual menu so that when a message is selected and right clicked the
user
can select an option from the pop up menu to move the selected message to
a
projects folder.

My intent was to have a folder dialog box open where the user can select
the
appropriate project's folder and then move the message from Outlook to the
selected folder. It appears the Outlook's .Move command will only allow
you
to move a message to an Outlook folder. Any ideas on how I might proceed
from here?

TIA,

Ken



  #4  
Old August 26th 08, 02:40 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Programmatically moving selected messages to network folder

You shouldn't be using objItem in SaveAs and relying on a default property.
Use something list objItem.Subject and then make sure to add the file
extension (objItem.Subject & ".MSG").

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Ken Warthen" wrote in message
...

Ken

I've been playing with SaveAs as you can see in my code below. When I
check
the destination folder there is an object there but it's label is
truncated,
there's no .msg extension, and no message icon, as you would get when
dragging and dropping messages directly into the folder. The explorer
window
also shows the file type as "File", where the messages that were dragged
and
dropped have a file type "Outlook Item".

Private Sub MoveToDSiProjectFolder()
On Error GoTo PROC_ERROR
Dim objNamespace As NameSpace
Dim objItem As MailItem
Dim objRecipient As Recipient
Dim strEntryID As String
Dim strSubject As String
Dim strSender As String
Dim strRecipient As String
Dim strDestinationFolder As String

strEntryID =
Application.ActiveExplorer.CommandBars.ActionContr ol.Parameter

If strEntryID "" Then
Set objNamespace = Application.GetNamespace("MAPI")
Set objItem = objNamespace.GetItemFromID(strEntryID)

With objItem
strSubject = .Subject
strSender = .SenderName
strRecipient = .ReceivedByName
End With
strDestinationFolder = "C:\Users\kwarthen\Desktop\Project
Related Mail\"
objItem.SaveAs strDestinationFolder & objItem, olMSG
End If

PROC_EXIT:
On Error GoTo 0
Set objRecipient = Nothing
Set objItem = Nothing
Set objNamespace = Nothing
Exit Sub
PROC_ERROR:
Call ShowError("modDSi", "MoveToDSiProjectFolder", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
Resume
End Sub





Ken


  #5  
Old August 26th 08, 03:28 PM posted to microsoft.public.outlook.program_vba
Ken Warthen
external usenet poster
 
Posts: 12
Default Programmatically moving selected messages to network folder

Ken,

Excellent! Of course, that worked. Thanks so much for your help. Any
suggestions on how to get user input on where to save the file? As I
understand it, Outlook does not support items like
Application.FileDialog(msoFileDialogFolderPicker). This is actually my first
venture in Outlook programming. Most of the development I've done in the
past has been in Access. Any suggestions on resources for getting up to
speed with Outlook programming?

Ken

"Ken Slovak - [MVP - Outlook]" wrote:

You shouldn't be using objItem in SaveAs and relying on a default property.
Use something list objItem.Subject and then make sure to add the file
extension (objItem.Subject & ".MSG").

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Ken Warthen" wrote in message
...

Ken

I've been playing with SaveAs as you can see in my code below. When I
check
the destination folder there is an object there but it's label is
truncated,
there's no .msg extension, and no message icon, as you would get when
dragging and dropping messages directly into the folder. The explorer
window
also shows the file type as "File", where the messages that were dragged
and
dropped have a file type "Outlook Item".

Private Sub MoveToDSiProjectFolder()
On Error GoTo PROC_ERROR
Dim objNamespace As NameSpace
Dim objItem As MailItem
Dim objRecipient As Recipient
Dim strEntryID As String
Dim strSubject As String
Dim strSender As String
Dim strRecipient As String
Dim strDestinationFolder As String

strEntryID =
Application.ActiveExplorer.CommandBars.ActionContr ol.Parameter

If strEntryID "" Then
Set objNamespace = Application.GetNamespace("MAPI")
Set objItem = objNamespace.GetItemFromID(strEntryID)

With objItem
strSubject = .Subject
strSender = .SenderName
strRecipient = .ReceivedByName
End With
strDestinationFolder = "C:\Users\kwarthen\Desktop\Project
Related Mail\"
objItem.SaveAs strDestinationFolder & objItem, olMSG
End If

PROC_EXIT:
On Error GoTo 0
Set objRecipient = Nothing
Set objItem = Nothing
Set objNamespace = Nothing
Exit Sub
PROC_ERROR:
Call ShowError("modDSi", "MoveToDSiProjectFolder", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
Resume
End Sub





Ken



  #6  
Old August 26th 08, 03:58 PM posted to microsoft.public.outlook.program_vba
Ken Warthen
external usenet poster
 
Posts: 12
Default Programmatically moving selected messages to network folder

Ken,

After additional testing it seems the code will work with some messages but
not others. Is there anything I need to look for in Subject fields that
might trigger an error?

Subject = "Mitch's father.msg" Works
Subject = "Confirmation: Getting Up and Going with Revit Structure 2009:
From Pilot to Production.msg" Triggers Error number -2147286788

Thanks again for your expertise.

Ken

"Ken Slovak - [MVP - Outlook]" wrote:

You shouldn't be using objItem in SaveAs and relying on a default property.
Use something list objItem.Subject and then make sure to add the file
extension (objItem.Subject & ".MSG").

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Ken Warthen" wrote in message
...

Ken

I've been playing with SaveAs as you can see in my code below. When I
check
the destination folder there is an object there but it's label is
truncated,
there's no .msg extension, and no message icon, as you would get when
dragging and dropping messages directly into the folder. The explorer
window
also shows the file type as "File", where the messages that were dragged
and
dropped have a file type "Outlook Item".

Private Sub MoveToDSiProjectFolder()
On Error GoTo PROC_ERROR
Dim objNamespace As NameSpace
Dim objItem As MailItem
Dim objRecipient As Recipient
Dim strEntryID As String
Dim strSubject As String
Dim strSender As String
Dim strRecipient As String
Dim strDestinationFolder As String

strEntryID =
Application.ActiveExplorer.CommandBars.ActionContr ol.Parameter

If strEntryID "" Then
Set objNamespace = Application.GetNamespace("MAPI")
Set objItem = objNamespace.GetItemFromID(strEntryID)

With objItem
strSubject = .Subject
strSender = .SenderName
strRecipient = .ReceivedByName
End With
strDestinationFolder = "C:\Users\kwarthen\Desktop\Project
Related Mail\"
objItem.SaveAs strDestinationFolder & objItem, olMSG
End If

PROC_EXIT:
On Error GoTo 0
Set objRecipient = Nothing
Set objItem = Nothing
Set objNamespace = Nothing
Exit Sub
PROC_ERROR:
Call ShowError("modDSi", "MoveToDSiProjectFolder", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
Resume
End Sub





Ken



  #7  
Old August 26th 08, 04:49 PM posted to microsoft.public.outlook.program_vba
Ken Warthen
external usenet poster
 
Posts: 12
Default Programmatically moving selected messages to network folder


Please disregard the above post, as a little more reading provided
information on invalid characters. After passing the subject to a function
to clean up any invalid characters, my code is working consistently.

I still haven't figured out how to get user input to select the appropriate
project folder to move (or save) the message to.

Ken


"Ken Warthen" wrote:

Ken,

After additional testing it seems the code will work with some messages but
not others. Is there anything I need to look for in Subject fields that
might trigger an error?

Subject = "Mitch's father.msg" Works
Subject = "Confirmation: Getting Up and Going with Revit Structure 2009:
From Pilot to Production.msg" Triggers Error number -2147286788

Thanks again for your expertise.

Ken

"Ken Slovak - [MVP - Outlook]" wrote:

You shouldn't be using objItem in SaveAs and relying on a default property.
Use something list objItem.Subject and then make sure to add the file
extension (objItem.Subject & ".MSG").

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Ken Warthen" wrote in message
...

Ken

I've been playing with SaveAs as you can see in my code below. When I
check
the destination folder there is an object there but it's label is
truncated,
there's no .msg extension, and no message icon, as you would get when
dragging and dropping messages directly into the folder. The explorer
window
also shows the file type as "File", where the messages that were dragged
and
dropped have a file type "Outlook Item".

Private Sub MoveToDSiProjectFolder()
On Error GoTo PROC_ERROR
Dim objNamespace As NameSpace
Dim objItem As MailItem
Dim objRecipient As Recipient
Dim strEntryID As String
Dim strSubject As String
Dim strSender As String
Dim strRecipient As String
Dim strDestinationFolder As String

strEntryID =
Application.ActiveExplorer.CommandBars.ActionContr ol.Parameter

If strEntryID "" Then
Set objNamespace = Application.GetNamespace("MAPI")
Set objItem = objNamespace.GetItemFromID(strEntryID)

With objItem
strSubject = .Subject
strSender = .SenderName
strRecipient = .ReceivedByName
End With
strDestinationFolder = "C:\Users\kwarthen\Desktop\Project
Related Mail\"
objItem.SaveAs strDestinationFolder & objItem, olMSG
End If

PROC_EXIT:
On Error GoTo 0
Set objRecipient = Nothing
Set objItem = Nothing
Set objNamespace = Nothing
Exit Sub
PROC_ERROR:
Call ShowError("modDSi", "MoveToDSiProjectFolder", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
Resume
End Sub





Ken



  #8  
Old August 26th 08, 06:19 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Programmatically moving selected messages to network folder

I use Win32 API calls to display the folder selector dialog, or if the code
will run on a machine with VB6 installed I use the common dialogs control
from that distribution. If I use Win32 calls I end up at common dialogs
anyway.

You can search for code that calls ComDlg32, I believe that VBAdvantage has
some samples for that. They probably use VB6 code but would work almost
identically in VBA code.

For general Outlook code samples you can't do better than
www.outlookcode.com. There's a wealth of sample code there as well as lots
of other information on Outlook programming.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Ken Warthen" wrote in message
...
Ken,

Excellent! Of course, that worked. Thanks so much for your help. Any
suggestions on how to get user input on where to save the file? As I
understand it, Outlook does not support items like
Application.FileDialog(msoFileDialogFolderPicker). This is actually my
first
venture in Outlook programming. Most of the development I've done in the
past has been in Access. Any suggestions on resources for getting up to
speed with Outlook programming?

Ken


 




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
When moving one (or more) messages from one folder to another, outlookinstead brings them into a new e-mail as attachments Outlook Guy[_2_] Outlook - General Queries 0 November 2nd 07 11:49 PM
Moving selected contact to archive folders Vanessa Outlook - Using Contacts 1 November 2nd 07 09:59 PM
Moving messages into a folder fails Jerry West Outlook - General Queries 5 February 10th 07 05:40 PM
Messages selected [email protected] Outlook and VBA 3 October 10th 06 04:44 PM
Create a search folder to look at all emails in one folder and selected criteria in other folders [email protected] Outlook - General Queries 1 April 10th 06 09:40 AM


All times are GMT +1. The time now is 01:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.