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

Status
Not open for further replies.
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 = systems@destination.aa

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
 
S

Sue Mosher [MVP]

You want to move the original message? I don't understand why you're not

simply using objItem.Move objTargetFolder.

Sue Mosher

"Albert" <help-me@skynet.be> wrote in message

news:%23J$w0mcdKHA.3300@TK2MSFTNGP02.phx.gbl...
> 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 = systems@destination.aa
> 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

>
 
A

Albert

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.

"Sue Mosher [MVP]" <suemvp@gmail.com> wrote in message

news:%23Ciau$ndKHA.5228@TK2MSFTNGP06.phx.gbl...
> You want to move the original message? I don't understand why you're not
> simply using objItem.Move objTargetFolder.

> > Sue Mosher
> > >

> "Albert" <help-me@skynet.be> wrote in message
> news:%23J$w0mcdKHA.3300@TK2MSFTNGP02.phx.gbl...
> >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 = systems@destination.aa
> > 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
>

>
>
>>


>
 
S

Sue Mosher [MVP]

"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

"Albert" <help-me@skynet.be> wrote in message

news:ef7d8k0dKHA.5608@TK2MSFTNGP05.phx.gbl...
> 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.

> "Sue Mosher [MVP]" <suemvp@gmail.com> wrote in message
> news:%23Ciau$ndKHA.5228@TK2MSFTNGP06.phx.gbl...
> > You want to move the original message? I don't understand why you're not
> > simply using objItem.Move objTargetFolder.
>

>> > > Sue Mosher
> > >> >> >
>
>> "Albert" <help-me@skynet.be> wrote in message
> > news:%23J$w0mcdKHA.3300@TK2MSFTNGP02.phx.gbl...
> >>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 = systems@destination.aa
> >> 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
 
A

Albert

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

"Sue Mosher [MVP]" <suemvp@gmail.com> wrote in message

news:OwcYoq0dKHA.4880@TK2MSFTNGP05.phx.gbl...
> "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
> > >

> "Albert" <help-me@skynet.be> wrote in message
> news:ef7d8k0dKHA.5608@TK2MSFTNGP05.phx.gbl...
> > 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.
>

>> "Sue Mosher [MVP]" <suemvp@gmail.com> wrote in message
> > news:%23Ciau$ndKHA.5228@TK2MSFTNGP06.phx.gbl...
> >> You want to move the original message? I don't understand why you're not
> >> simply using objItem.Move objTargetFolder.
> >
>>> > >> Sue Mosher
> >> >>> >>> >>
>>
>>> "Albert" <help-me@skynet.be> wrote in message
> >> news:%23J$w0mcdKHA.3300@TK2MSFTNGP02.phx.gbl...
> >>>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 = systems@destination.aa
> >>> 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


>
 
A

Albert

Re: book with basics of using vba ?

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

"Sue Mosher [MVP]" <suemvp@gmail.com> wrote in message

news:OwcYoq0dKHA.4880@TK2MSFTNGP05.phx.gbl...
> "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
> > >

> "Albert" <help-me@skynet.be> wrote in message
> news:ef7d8k0dKHA.5608@TK2MSFTNGP05.phx.gbl...
> > 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.
>

>> "Sue Mosher [MVP]" <suemvp@gmail.com> wrote in message
> > news:%23Ciau$ndKHA.5228@TK2MSFTNGP06.phx.gbl...
> >> You want to move the original message? I don't understand why you're not
> >> simply using objItem.Move objTargetFolder.
> >
>>> > >> Sue Mosher
> >> >>> >>> >>
>>
>>> "Albert" <help-me@skynet.be> wrote in message
> >> news:%23J$w0mcdKHA.3300@TK2MSFTNGP02.phx.gbl...
> >>>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 = systems@destination.aa
> >>> 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


>
 
S

Sue Mosher [MVP]

Re: book with basics of using vba ?

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.

Sue Mosher

"Albert" <albert@gmail.com> wrote in message

news:u6PLkB$dKHA.5568@TK2MSFTNGP02.phx.gbl...

> 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 ?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
E Search for folder by key in subject then move new message to related folder Outlook VBA and Custom Forms 1
mrmmickle1 UserProperties VBA to move message to another folder Outlook VBA and Custom Forms 7
M Automatically move Outlook message to the specific folder when click on reply to all Using Outlook 4
H move to folder rule corrupts message Using Outlook 3
I Automating message move between folders Outlook VBA and Custom Forms 0
T What code to use to move the custom field values to message body when sending e-mail ? Outlook VBA and Custom Forms 8
M Error message: "Cannot move the items..." Using Outlook 2
M Outlook 2010 IMAP account message move behavior Using Outlook 15
mikolajek Outlook 2013 IMAP actions (message move / delete etc.) significantly delayed Using Outlook 0
D Error message - Cannot move the items.... Using Outlook 1
J Move message skips messages when looping through mailbox Outlook VBA and Custom Forms 2
A How to catch Message Move Event. Outlook VBA and Custom Forms 10
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 10
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
J Dopey move - deleted profile Using Outlook 1
GregS Outlook 2016 Move Outlook to new computer? Using Outlook 4
witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 7
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
G Cannot Move Autocomplete File to New Computer Using Outlook 15
M Move to Folder Using Outlook 1
P Move emails between 2 mailboxes. Using Outlook 0
C Copy Move item won't work Outlook VBA and Custom Forms 2
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
Commodore Move turns into "copy" Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
M move to iCloud not working in outlook calendar Using Outlook 12
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
C Can't move folder, the folder is full Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
A Move email items based on a list of email addresses Outlook VBA and Custom Forms 40
T Move calendar invites to new calendar Using Outlook 5
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
K Outlook Rules: Move a Copy Using Outlook 4
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
N Move emails of same conversation to same subfolder Using Outlook 6
P when i move inbox mails to another folder in outlook the mail disappears Using Outlook 1
Peter H Williams How to Move Mail item after processing Outlook VBA and Custom Forms 5
D Move Emails between Folders in Separate Mailbox Outlook VBA and Custom Forms 12
I Outlook 2013 Any way to move .OST file to new system? Using Outlook.com accounts in Outlook 5
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
F "Move to" O365 feature to Outlook client via VBA Outlook VBA and Custom Forms 4

Similar threads

Top