WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Programmatically moving selected messages to network folder

 
   Home -> Office -> Programming VBA RSS
Next:  macro to automatically add invitee to new appoint..  
Author Message
Ken Warthen

External


Since: Nov 09, 2007
Posts: 18



(Msg. 1) Posted: Mon Aug 25, 2008 11:32 am
Post subject: Programmatically moving selected messages to network folder
Archived from groups: microsoft>public>outlook>program_vba (more info?)

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
Back to top
Login to vote
Ken Slovak - [MVP - Outlo

External


Since: Oct 17, 2003
Posts: 2898



(Msg. 2) Posted: Mon Aug 25, 2008 4:31 pm
Post subject: Re: Programmatically moving selected messages to network folder [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <KenWarthen RemoveThis @discussions.microsoft.com> wrote in message
news:86B01335-D704-4822-B191-C2BB94349F26@microsoft.com...
> 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
Back to top
Login to vote
Ken Warthen

External


Since: Nov 09, 2007
Posts: 18



(Msg. 3) Posted: Mon Aug 25, 2008 4:31 pm
Post subject: Re: Programmatically moving selected messages to network folder [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.ActionControl.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" <KenWarthen DeleteThis @discussions.microsoft.com> wrote in message
> news:86B01335-D704-4822-B191-C2BB94349F26@microsoft.com...
> > 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
>
>
Back to top
Login to vote
Ken Slovak - [MVP - Outlo

External


Since: Oct 17, 2003
Posts: 2898



(Msg. 4) Posted: Tue Aug 26, 2008 9:40 am
Post subject: Re: Programmatically moving selected messages to network folder [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <KenWarthen RemoveThis @discussions.microsoft.com> wrote in message
news:1D9A5056-2FBE-47D1-A61C-116CC0186759@microsoft.com...
>
> 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.ActionControl.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
Back to top
Login to vote
Ken Warthen

External


Since: Nov 09, 2007
Posts: 18



(Msg. 5) Posted: Tue Aug 26, 2008 9:40 am
Post subject: Re: Programmatically moving selected messages to network folder [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <KenWarthen.DeleteThis@discussions.microsoft.com> wrote in message
> news:1D9A5056-2FBE-47D1-A61C-116CC0186759@microsoft.com...
> >
> > 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.ActionControl.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
>
>
Back to top
Login to vote
Ken Warthen

External


Since: Nov 09, 2007
Posts: 18



(Msg. 6) Posted: Tue Aug 26, 2008 9:40 am
Post subject: Re: Programmatically moving selected messages to network folder [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <KenWarthen.TakeThisOut@discussions.microsoft.com> wrote in message
> news:1D9A5056-2FBE-47D1-A61C-116CC0186759@microsoft.com...
> >
> > 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.ActionControl.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
>
>
Back to top
Login to vote
Ken Warthen

External


Since: Nov 09, 2007
Posts: 18



(Msg. 7) Posted: Tue Aug 26, 2008 9:40 am
Post subject: Re: Programmatically moving selected messages to network folder [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <KenWarthen.RemoveThis@discussions.microsoft.com> wrote in message
> > news:1D9A5056-2FBE-47D1-A61C-116CC0186759@microsoft.com...
> > >
> > > 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.ActionControl.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
> >
> >
Back to top
Login to vote
Ken Slovak - [MVP - Outlo

External


Since: Oct 17, 2003
Posts: 2898



(Msg. 8) Posted: Tue Aug 26, 2008 1:19 pm
Post subject: Re: Programmatically moving selected messages to network folder [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <KenWarthen DeleteThis @discussions.microsoft.com> wrote in message
news:BF59AFF8-8FA3-4CD9-9E42-32B73D15ADEA@microsoft.com...
> 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
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET