How do I move a message to a folder after forwarding ?

  • Thread starter Thread starter Albert
  • Start date Start date
A

Albert

I am forwarding a message then after sending want to move it to the TRUVO
folder. Can someone help, what have I done wrong ??

thanks .. Alb

Sub ForwardHome()
Rem forward a highlighted email to the email address nominated
Rem to work correctly the Function GetCurrentItem() must also be included
Dim ObjMail As Outlook.MailItem
Set objItem = GetCurrentItem()
Set ObjMail = objItem.Forward
ObjMail.To = (e-mail address removed)
ObjMail.Send
Set objItem = Nothing
Set ObjMail = Nothing

Rem this first part works okay !

Rem now next bit should move highlighted email to nominated folder
"Personal folders/TRUVO" after being sent
Set oInboxItems = bjNS.GetDefaultFolder(olFolder"Personal folders").Items
Set olns = Item.Application.GetNamespace("MAPI")
Set objTargetFolder = Outlook.Session.PickFolder
Set objCurItem = oInboxItems.Item(1)
Set objCurItem = objCurItem.Move(objTRUVO)

End Sub

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
End Select
End Function
 
You want to move the original message? I don't understand why you're not
simply using objItem.Move objTargetFolder.
 
Thanks, but I tried that. I had the following

Set objTargetFolder = "Personal Folders/TEST"
ObjItem.Move objTargetFolder

but it wouldn't work, so I searched www for an alternative and found the
code I previously posted (which also didn't work) together with some
explanation that seemed to say that I had to use a MAPI folder. Sorry but
I'm a bit new at this !

Alb.
 
"Personal Folders/TEST" is a string. You can't wish it into a Folder or
MAPIFolder object. However, your code already has a statement that returns a
valid objFolder object:

Set objTargetFolder = Application.Session.PickFolder

Why not use that? Or are you trying to move the item always to the same
folder? If that's the case, you need to walk the folder hierarchy using the
Folders collections or use a function that does that for you. For examples,
see:

http://www.outlookcode.com/codedetail.aspx?id=628 - uses a folder path
string
http://www.outlookcode.com/codedetail.aspx?id=492 - searches for a folder by
name

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Yes, I am trying to move the item always to the same folder. I can get the
PickFolder option to work, but that doesn't fit my situation, hence my
previous try to use the MAPI option which I still don't really understand.
However, thanks for the guidance, I will study the two examples. Obviously
this is not for beginners like me !

Alb
 
Dear Sue

I see that you have some books for sale on how to use vba. I am sure I would
benefit .. are the books posted to me or electronic download ? Also, can you
suggest a good basic book that would point me in the right direction using
vba ? Is the vba used in Outlook2003 the same as Outlook 2007 and other
Office applications generally ?

thanks .. Alb
 
My latest book is available in both hard-copy and Kindle versions, plus an
electronic version (that looks quite costly) from
http://www.sciencedirect.com/science/book/9781555583460. You can also search
for particular topics in it at Google Books.

VBA is the same in every Office application. My books cover the VBA basics
that are most useful for Outlook programming. If you need a broader
introduction, I like Paul McFedries' Absolute Beginner's Guide to VBA.
 
Back
Top