|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Forward mail without using the default signatureHi I am using the following code to auto forward my OL mails to a web email address:- ---------------------------------------------------------- Public WithEvents myOlItems As Outlook.Items Public Sub Application_Startup() ' Reference the items in the Inbox. Because myOlItems is declared ' "WithEvents" the ItemAdd event will fire below. MsgBox "Running Application_Startup" Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items End Sub Private Sub myOlItems_ItemAdd(ByVal Item As Object) ' Check to make sure it is an Outlook mail message, otherwise ' subsequent code will probably fail depending on what type ' of item it is. If TypeName(Item) = "MailItem" Then ' Forward the item just received Set myForward = Item.Forward ' Address the message myForward.Recipients.Add "alastair.can***@googlemail.com" ' Send it myForward.Send End If End Sub ------------------------------- Is there a way I can send the forwarded mail without using my default signature? Many thanks Alastair Not unless you scan the email item and remove it using string functions,
either on Body or HTMLBody (depending on the type of item). -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "badatvba" <badat***@discussions.microsoft.com> wrote in message news:7B09B621-18C7-4081-A17E-196F20E5628B@microsoft.com... > Outlook 2003 SP2 > > Hi I am using the following code to auto forward my OL mails to a web > address:- > > ---------------------------------------------------------- > Public WithEvents myOlItems As Outlook.Items > > Public Sub Application_Startup() > > ' Reference the items in the Inbox. Because myOlItems is declared > ' "WithEvents" the ItemAdd event will fire below. > MsgBox "Running Application_Startup" > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > End Sub > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > ' Check to make sure it is an Outlook mail message, otherwise > ' subsequent code will probably fail depending on what type > ' of item it is. > If TypeName(Item) = "MailItem" Then > > ' Forward the item just received > Set myForward = Item.Forward > > ' Address the message > myForward.Recipients.Add "alastair.can***@googlemail.com" > > ' Send it > myForward.Send > > End If > > End Sub > > ------------------------------- > Is there a way I can send the forwarded mail without using my default > signature? > > Many thanks > > Alastair Ken,
thanks again for your input. I have revised my thinking regading this issue and would like to move froma simple 'forward' of the amil items to the following:- extract from the original mail:- From CC Subject Body Then create a new mail item as follows:- To: <my mail address> Subject: Re: <original subject> Body: <original body> I know I could - and *should* - research this myself, but I am anxious to get this in place asap. best regards Alastair Show quoteHide quote "Ken Slovak - [MVP - Outlook]" wrote: > Not unless you scan the email item and remove it using string functions, > either on Body or HTMLBody (depending on the type of item). > > -- > 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 > > > "badatvba" <badat***@discussions.microsoft.com> wrote in message > news:7B09B621-18C7-4081-A17E-196F20E5628B@microsoft.com... > > Outlook 2003 SP2 > > > > Hi I am using the following code to auto forward my OL mails to a web > > address:- > > > > ---------------------------------------------------------- > > Public WithEvents myOlItems As Outlook.Items > > > > Public Sub Application_Startup() > > > > ' Reference the items in the Inbox. Because myOlItems is declared > > ' "WithEvents" the ItemAdd event will fire below. > > MsgBox "Running Application_Startup" > > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > > > End Sub > > > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > > > ' Check to make sure it is an Outlook mail message, otherwise > > ' subsequent code will probably fail depending on what type > > ' of item it is. > > If TypeName(Item) = "MailItem" Then > > > > ' Forward the item just received > > Set myForward = Item.Forward > > > > ' Address the message > > myForward.Recipients.Add "alastair.can***@googlemail.com" > > > > ' Send it > > myForward.Send > > > > End If > > > > End Sub > > > > ------------------------------- > > Is there a way I can send the forwarded mail without using my default > > signature? > > > > Many thanks > > > > Alastair > > Hi ,
I have noticed an omission in my original post the body of my new mail item should contain:- <original CC> <original body> cheers Show quoteHide quote "badatvba" wrote: > Ken, > > thanks again for your input. I have revised my thinking regading this issue > and would like to move froma simple 'forward' of the amil items to the > following:- > > extract from the original mail:- > From > CC > Subject > Body > > Then create a new mail item as follows:- > To: <my mail address> > Subject: Re: <original subject> > Body: <original body> > > I know I could - and *should* - research this myself, but I am anxious to > get this in place asap. > > best regards > > Alastair > > "Ken Slovak - [MVP - Outlook]" wrote: > > > Not unless you scan the email item and remove it using string functions, > > either on Body or HTMLBody (depending on the type of item). > > > > -- > > 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 > > > > > > "badatvba" <badat***@discussions.microsoft.com> wrote in message > > news:7B09B621-18C7-4081-A17E-196F20E5628B@microsoft.com... > > > Outlook 2003 SP2 > > > > > > Hi I am using the following code to auto forward my OL mails to a web > > > address:- > > > > > > ---------------------------------------------------------- > > > Public WithEvents myOlItems As Outlook.Items > > > > > > Public Sub Application_Startup() > > > > > > ' Reference the items in the Inbox. Because myOlItems is declared > > > ' "WithEvents" the ItemAdd event will fire below. > > > MsgBox "Running Application_Startup" > > > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > > > > > End Sub > > > > > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > > > > > ' Check to make sure it is an Outlook mail message, otherwise > > > ' subsequent code will probably fail depending on what type > > > ' of item it is. > > > If TypeName(Item) = "MailItem" Then > > > > > > ' Forward the item just received > > > Set myForward = Item.Forward > > > > > > ' Address the message > > > myForward.Recipients.Add "alastair.can***@googlemail.com" > > > > > > ' Send it > > > myForward.Send > > > > > > End If > > > > > > End Sub > > > > > > ------------------------------- > > > Is there a way I can send the forwarded mail without using my default > > > signature? > > > > > > Many thanks > > > > > > Alastair > > > > Get the ConversationIndex and ConversationTopic properties of the new
message. Find the original by looking for all items with that ConversationTopic. Each item in a thread adds its own date/time struct to the ConversationIndex property, so the parent of the new item would be one struct shorter than the new item's ConversationIndex property length. Once you have the parent item you can then extract whatever properties you want from that item, including Body and or HTMLBody, Subject, etc. Some properties you may want might have to be extracted from the Recipients collection of the parent item if what's available directly on the item doesn't have the information you want. -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "badatvba" <badat***@discussions.microsoft.com> wrote in message news:AFA02A9C-0789-4676-BBFB-BB0236485A55@microsoft.com... > Ken, > > thanks again for your input. I have revised my thinking regading this > issue > and would like to move froma simple 'forward' of the amil items to the > following:- > > extract from the original mail:- > From > CC > Subject > Body > > Then create a new mail item as follows:- > To: <my mail address> > Subject: Re: <original subject> > Body: <original body> > > I know I could - and *should* - research this myself, but I am anxious to > get this in place asap. > > best regards > > Alastair Thanks for this Ken,
I will follow this up and maybe will need your excellent advice shortly...?! cheers Alastair Show quoteHide quote "Ken Slovak - [MVP - Outlook]" wrote: > Get the ConversationIndex and ConversationTopic properties of the new > message. Find the original by looking for all items with that > ConversationTopic. Each item in a thread adds its own date/time struct to > the ConversationIndex property, so the parent of the new item would be one > struct shorter than the new item's ConversationIndex property length. > > Once you have the parent item you can then extract whatever properties you > want from that item, including Body and or HTMLBody, Subject, etc. Some > properties you may want might have to be extracted from the Recipients > collection of the parent item if what's available directly on the item > doesn't have the information you want. > > -- > 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 > > > "badatvba" <badat***@discussions.microsoft.com> wrote in message > news:AFA02A9C-0789-4676-BBFB-BB0236485A55@microsoft.com... > > Ken, > > > > thanks again for your input. I have revised my thinking regading this > > issue > > and would like to move froma simple 'forward' of the amil items to the > > following:- > > > > extract from the original mail:- > > From > > CC > > Subject > > Body > > > > Then create a new mail item as follows:- > > To: <my mail address> > > Subject: Re: <original subject> > > Body: <original body> > > > > I know I could - and *should* - research this myself, but I am anxious to > > get this in place asap. > > > > best regards > > > > Alastair > > Hi,
I have modified the code - just for debugging purposes - to try to extract the sender, sender email and body of a receoived newly received mail with a view to constructing a new one from tis info. --------------------------------------- Public WithEvents myOlItems As Outlook.Items Public Sub Application_Startup() ' Reference the items in the Inbox. Because myOlItems is declared ' "WithEvents" the ItemAdd event will fire below. MsgBox "Running Application_Startup" Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items End Sub Private Sub myOlItems_ItemAdd(ByVal Item As Object) Dim mysender As String Dim myemail As String Dim mybody As String ' Check to make sure it is an Outlook mail message, otherwise ' subsequent code will probably fail depending on what type ' of item it is. If TypeName(Item) = "MailItem" Then ' Extract info from the mailItem Set mysender = Item.SenderEmailAddress Set mysender = Item.SenderName Set mybody = Item.body MsgBox myemail MsgBox mysender MsgBox mybody ' Forward the item just received Set myForward = Item.Forward ' Address the message myForward.Recipients.Add "alastair.can***@googlemail.com" ' Send it myForward.Send End If End Sub -------------------------------------------- I get an error " complile error - object required" Any suggestions? Alastair Show quoteHide quote "badatvba" wrote: > Thanks for this Ken, > > I will follow this up and maybe will need your excellent advice shortly...?! > > cheers > > Alastair > > "Ken Slovak - [MVP - Outlook]" wrote: > > > Get the ConversationIndex and ConversationTopic properties of the new > > message. Find the original by looking for all items with that > > ConversationTopic. Each item in a thread adds its own date/time struct to > > the ConversationIndex property, so the parent of the new item would be one > > struct shorter than the new item's ConversationIndex property length. > > > > Once you have the parent item you can then extract whatever properties you > > want from that item, including Body and or HTMLBody, Subject, etc. Some > > properties you may want might have to be extracted from the Recipients > > collection of the parent item if what's available directly on the item > > doesn't have the information you want. > > > > -- > > 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 > > > > > > "badatvba" <badat***@discussions.microsoft.com> wrote in message > > news:AFA02A9C-0789-4676-BBFB-BB0236485A55@microsoft.com... > > > Ken, > > > > > > thanks again for your input. I have revised my thinking regading this > > > issue > > > and would like to move froma simple 'forward' of the amil items to the > > > following:- > > > > > > extract from the original mail:- > > > From > > > CC > > > Subject > > > Body > > > > > > Then create a new mail item as follows:- > > > To: <my mail address> > > > Subject: Re: <original subject> > > > Body: <original body> > > > > > > I know I could - and *should* - research this myself, but I am anxious to > > > get this in place asap. > > > > > > best regards > > > > > > Alastair > > > > What line fires the error?
-- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "badatvba" <badat***@discussions.microsoft.com> wrote in message news:12FD6707-1D72-4B88-8FEA-04F644CA6868@microsoft.com... > Hi, > > I have modified the code - just for debugging purposes - to try to extract > the sender, sender email and body of a receoived newly received mail with > a > view to constructing a new one from tis info. > > --------------------------------------- > Public WithEvents myOlItems As Outlook.Items > > Public Sub Application_Startup() > > ' Reference the items in the Inbox. Because myOlItems is declared > ' "WithEvents" the ItemAdd event will fire below. > MsgBox "Running Application_Startup" > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > End Sub > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > Dim mysender As String > Dim myemail As String > Dim mybody As String > > ' Check to make sure it is an Outlook mail message, otherwise > ' subsequent code will probably fail depending on what type > ' of item it is. > If TypeName(Item) = "MailItem" Then > > ' Extract info from the mailItem > Set mysender = Item.SenderEmailAddress > Set mysender = Item.SenderName > Set mybody = Item.body > > MsgBox myemail > MsgBox mysender > MsgBox mybody > > > ' Forward the item just received > Set myForward = Item.Forward > > ' Address the message > myForward.Recipients.Add "alastair.can***@googlemail.com" > > ' Send it > myForward.Send > > End If > > End Sub > > -------------------------------------------- > > I get an error > > " complile error - object required" > > Any suggestions? > Hi Ken,
this line is highlighted in yellow:- Private Sub myOlItems_ItemAdd(ByVal Item As Object) this in black Set mysender = Item.SenderEmailAddress - note only the 'mysender' text best regards Alastair Show quoteHide quote "Ken Slovak - [MVP - Outlook]" wrote: > What line fires the error? > > -- > 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 > > > "badatvba" <badat***@discussions.microsoft.com> wrote in message > news:12FD6707-1D72-4B88-8FEA-04F644CA6868@microsoft.com... > > Hi, > > > > I have modified the code - just for debugging purposes - to try to extract > > the sender, sender email and body of a receoived newly received mail with > > a > > view to constructing a new one from tis info. > > > > --------------------------------------- > > Public WithEvents myOlItems As Outlook.Items > > > > Public Sub Application_Startup() > > > > ' Reference the items in the Inbox. Because myOlItems is declared > > ' "WithEvents" the ItemAdd event will fire below. > > MsgBox "Running Application_Startup" > > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > > > End Sub > > > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > > > Dim mysender As String > > Dim myemail As String > > Dim mybody As String > > > > ' Check to make sure it is an Outlook mail message, otherwise > > ' subsequent code will probably fail depending on what type > > ' of item it is. > > If TypeName(Item) = "MailItem" Then > > > > ' Extract info from the mailItem > > Set mysender = Item.SenderEmailAddress > > Set mysender = Item.SenderName > > Set mybody = Item.body > > > > MsgBox myemail > > MsgBox mysender > > MsgBox mybody > > > > > > ' Forward the item just received > > Set myForward = Item.Forward > > > > ' Address the message > > myForward.Recipients.Add "alastair.can***@googlemail.com" > > > > ' Send it > > myForward.Send > > > > End If > > > > End Sub > > > > -------------------------------------------- > > > > I get an error > > > > " complile error - object required" > > > > Any suggestions? > > > > Try not using Set on any string values, just assign them. You only use Set
when setting the instantiation of an Object of some sort, not strings or numerics or Booleans, etc. -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "badatvba" <badat***@discussions.microsoft.com> wrote in message news:69BFC9EF-232F-4FDF-BBBC-71823E5C96BC@microsoft.com... > Hi Ken, > > this line is highlighted in yellow:- > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > this in black > > Set mysender = Item.SenderEmailAddress - note only the 'mysender' text > > best regards > > Alastair Hi,
I have modified the code as below. However, it does not complain but nor does it do what I want - It actually seems to do nothing. Please could you advise. BTW the MsgBox entries (currently commented out) show the correct info. best regards Alastair --------------------------------------------------------------- Public WithEvents myOlItems As Outlook.Items Public Sub Application_Startup() ' Reference the items in the Inbox. Because myOlItems is declared ' "WithEvents" the ItemAdd event will fire below. MsgBox "Running Application_Startup" Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items End Sub Private Sub myOlItems_ItemAdd(ByVal Item As Object) ' Check to make sure it is an Outlook mail message, otherwise ' subsequent code will probably fail depending on what type ' of item it is. If TypeName(Item) = "MailItem" Then 'Extract info from the mailItem myemail = Item.SenderEmailAddress mysender = Item.SenderName mybody = Item.body 'MsgBox myemail 'MsgBox mysender 'MsgBox mybody Set myOlApp = CreateObject("Outlook.Application") Set myItem = myOlApp.CreateItem(olMailItem) Set myItem.To = "alastair.can***@googlemail.com" Set myItem.Body = mybody myItem.Send ' Forward the item just received ' Set myForward = Item.Forward ' Address the message ' myForward.Recipients.Add "alastair.can***@googlemail.com" ' Send it ' myForward.Send End If End Sub _______________________________________________________ Show quoteHide quote "Ken Slovak - [MVP - Outlook]" wrote: > Try not using Set on any string values, just assign them. You only use Set > when setting the instantiation of an Object of some sort, not strings or > numerics or Booleans, etc. > > -- > 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 > > > "badatvba" <badat***@discussions.microsoft.com> wrote in message > news:69BFC9EF-232F-4FDF-BBBC-71823E5C96BC@microsoft.com... > > Hi Ken, > > > > this line is highlighted in yellow:- > > > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > > > this in black > > > > Set mysender = Item.SenderEmailAddress - note only the 'mysender' text > > > > best regards > > > > Alastair > > In Outlook VBA code never, ever create a new Application object, use the
intrinsic Application object. Set myItem = Application.CreateItem(olMailItem) -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "badatvba" <badat***@discussions.microsoft.com> wrote in message news:1F0EA49B-AF33-4A98-A6AE-DE17FE710590@microsoft.com... > Hi, > > I have modified the code as below. However, it does not complain but nor > does it do what I want - It actually seems to do nothing. Please could you > advise. > > BTW the MsgBox entries (currently commented out) show the correct info. > > best regards > > Alastair > --------------------------------------------------------------- > Public WithEvents myOlItems As Outlook.Items > > Public Sub Application_Startup() > > ' Reference the items in the Inbox. Because myOlItems is declared > ' "WithEvents" the ItemAdd event will fire below. > MsgBox "Running Application_Startup" > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > End Sub > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > > > ' Check to make sure it is an Outlook mail message, otherwise > ' subsequent code will probably fail depending on what type > ' of item it is. > If TypeName(Item) = "MailItem" Then > > 'Extract info from the mailItem > myemail = Item.SenderEmailAddress > mysender = Item.SenderName > mybody = Item.body > > 'MsgBox myemail > 'MsgBox mysender > 'MsgBox mybody > > Set myOlApp = CreateObject("Outlook.Application") > Set myItem = myOlApp.CreateItem(olMailItem) > > Set myItem.To = "alastair.can***@googlemail.com" > Set myItem.Body = mybody > myItem.Send > > > > ' Forward the item just received > ' Set myForward = Item.Forward > > ' Address the message > ' myForward.Recipients.Add "alastair.can***@googlemail.com" > > ' Send it > ' myForward.Send > > End If > > End Sub Hi Ken,
my code now looks like this but it still does not complain *or* do what I want. Apologies for being a pain but if I can get this running it will be a real boon to me. Any advice/guidance would be most welcome Alastair -------------------------------- Public WithEvents myOlItems As Outlook.Items Public Sub Application_Startup() ' Reference the items in the Inbox. Because myOlItems is declared ' "WithEvents" the ItemAdd event will fire below. MsgBox "Running Application_Startup" Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items End Sub Private Sub myOlItems_ItemAdd(ByVal Item As Object) ' Check to make sure it is an Outlook mail message, otherwise ' subsequent code will probably fail depending on what type ' of item it is. If TypeName(Item) = "MailItem" Then 'Extract info from the mailItem myemail = Item.SenderEmailAddress mysender = Item.SenderName mybody = Item.body Set myItem = Application.CreateItem(olMailItem) myItem.To = "alastair.can***@googlemail.com" myItem.body = mybody myItem.Send ' Forward the item just received ' Set myForward = Item.Forward ' Address the message ' myForward.Recipients.Add "alastair.can***@googlemail.com" ' Send it ' myForward.Send End If End Sub --------------------------------------------------------------------------------- Show quoteHide quote "Ken Slovak - [MVP - Outlook]" wrote: > In Outlook VBA code never, ever create a new Application object, use the > intrinsic Application object. > > Set myItem = Application.CreateItem(olMailItem) > > > -- > 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 > > > "badatvba" <badat***@discussions.microsoft.com> wrote in message > news:1F0EA49B-AF33-4A98-A6AE-DE17FE710590@microsoft.com... > > Hi, > > > > I have modified the code as below. However, it does not complain but nor > > does it do what I want - It actually seems to do nothing. Please could you > > advise. > > > > BTW the MsgBox entries (currently commented out) show the correct info. > > > > best regards > > > > Alastair > > --------------------------------------------------------------- > > Public WithEvents myOlItems As Outlook.Items > > > > Public Sub Application_Startup() > > > > ' Reference the items in the Inbox. Because myOlItems is declared > > ' "WithEvents" the ItemAdd event will fire below. > > MsgBox "Running Application_Startup" > > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > > > End Sub > > > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > > > > > > > ' Check to make sure it is an Outlook mail message, otherwise > > ' subsequent code will probably fail depending on what type > > ' of item it is. > > If TypeName(Item) = "MailItem" Then > > > > 'Extract info from the mailItem > > myemail = Item.SenderEmailAddress > > mysender = Item.SenderName > > mybody = Item.body > > > > 'MsgBox myemail > > 'MsgBox mysender > > 'MsgBox mybody > > > > Set myOlApp = CreateObject("Outlook.Application") > > Set myItem = myOlApp.CreateItem(olMailItem) > > > > Set myItem.To = "alastair.can***@googlemail.com" > > Set myItem.Body = mybody > > myItem.Send > > > > > > > > ' Forward the item just received > > ' Set myForward = Item.Forward > > > > ' Address the message > > ' myForward.Recipients.Add "alastair.can***@googlemail.com" > > > > ' Send it > > ' myForward.Send > > > > End If > > > > End Sub > > Try this:
'previous code Set myItem = Application.CreateItem(olMailItem) Dim oRecip As Outlook.Recipient Set oRecip = myItem.Recipients.Add("alastair.can***@googlemail.com") oRecip.Resolve myItem.body = mybody myItem.Subject = Item.Subject myItem.Send -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "badatvba" <badat***@discussions.microsoft.com> wrote in message news:2674CA00-69C9-4FE1-AE5C-FCB9A3113D89@microsoft.com... > Hi Ken, > > my code now looks like this but it still does not complain *or* do what I > want. Apologies for being a pain but if I can get this running it will be > a > real boon to me. > > Any advice/guidance would be most welcome > > Alastair > -------------------------------- > Public WithEvents myOlItems As Outlook.Items > > Public Sub Application_Startup() > > ' Reference the items in the Inbox. Because myOlItems is declared > ' "WithEvents" the ItemAdd event will fire below. > MsgBox "Running Application_Startup" > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > End Sub > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > > > ' Check to make sure it is an Outlook mail message, otherwise > ' subsequent code will probably fail depending on what type > ' of item it is. > If TypeName(Item) = "MailItem" Then > > 'Extract info from the mailItem > myemail = Item.SenderEmailAddress > mysender = Item.SenderName > mybody = Item.body > > Set myItem = Application.CreateItem(olMailItem) > myItem.To = "alastair.can***@googlemail.com" > myItem.body = mybody > myItem.Send > > > > ' Forward the item just received > ' Set myForward = Item.Forward > > ' Address the message > ' myForward.Recipients.Add "alastair.can***@googlemail.com" > > ' Send it > ' myForward.Send > > End If > > End Sub Hello Ken,
thanks to you I am now able to do what I wanted to do. However.............there is always a but isn't there! Could you give me some pointers as to how to *move* a mail item from the inbox to another folder based on the sender's name. I have seen another thread about this but I confess I did not really understand the code used/suggested. Here I am 52 years old and only just learning a bit of VBA!! best regards Alastair Show quoteHide quote "Ken Slovak - [MVP - Outlook]" wrote: > Try this: > > 'previous code > Set myItem = Application.CreateItem(olMailItem) > Dim oRecip As Outlook.Recipient > Set oRecip = myItem.Recipients.Add("alastair.can***@googlemail.com") > oRecip.Resolve > myItem.body = mybody > myItem.Subject = Item.Subject > myItem.Send > > -- > 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 > > > "badatvba" <badat***@discussions.microsoft.com> wrote in message > news:2674CA00-69C9-4FE1-AE5C-FCB9A3113D89@microsoft.com... > > Hi Ken, > > > > my code now looks like this but it still does not complain *or* do what I > > want. Apologies for being a pain but if I can get this running it will be > > a > > real boon to me. > > > > Any advice/guidance would be most welcome > > > > Alastair > > -------------------------------- > > Public WithEvents myOlItems As Outlook.Items > > > > Public Sub Application_Startup() > > > > ' Reference the items in the Inbox. Because myOlItems is declared > > ' "WithEvents" the ItemAdd event will fire below. > > MsgBox "Running Application_Startup" > > Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items > > > > End Sub > > > > Private Sub myOlItems_ItemAdd(ByVal Item As Object) > > > > > > > > ' Check to make sure it is an Outlook mail message, otherwise > > ' subsequent code will probably fail depending on what type > > ' of item it is. > > If TypeName(Item) = "MailItem" Then > > > > 'Extract info from the mailItem > > myemail = Item.SenderEmailAddress > > mysender = Item.SenderName > > mybody = Item.body > > > > Set myItem = Application.CreateItem(olMailItem) > > myItem.To = "alastair.can***@googlemail.com" > > myItem.body = mybody > > myItem.Send > > > > > > > > ' Forward the item just received > > ' Set myForward = Item.Forward > > > > ' Address the message > > ' myForward.Recipients.Add "alastair.can***@googlemail.com" > > > > ' Send it > > ' myForward.Send > > > > End If > > > > End Sub > > To move an item you use its Move() method. It takes a target folder argument
that's an Outlook.MAPIFolder object. It returns to you the newly moved item as a return value. How you get the folder that's the target depends on lots of things. Where would this target folder be located? Is it under Inbox? Is there more than one possible target folder? Say you get the SenderName, which you know how to do already. That name will determine the target folder, which is a subfolder of Inbox. Here's how that would be done, where mysender is the SenderName: Dim oNS As Outlook.NameSpace Set oNS = Application.GetNameSpace("MAPI") Dim oTarget As Outlook.MAPIFolder Dim oInbox As Outlook.MAPIFolder Set oInbox = oNS.GetDefaultFolder(olFolderInbox) Dim blnFound As Boolean blnFound = False For Each oTarget In oInbox.Folders If oTarget.Name = mysender Then 'found it blnFound = True Exit For Next If Not blnFound Then Set oTarget = oInbox.Folders.Add(mysender, olFolderInbox) ' add as mail folder End If Dim oMovedItem As Outlook.MailItem Set oMovedItem = Item.Move(oTarget) That code would go in the myOlItems_ItemAdd() procedure. www.outlookcode.com has tons of samples of all sorts of Outlook coding, you might want to look around there. You'll learn a lot. .. -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "badatvba" <badat***@discussions.microsoft.com> wrote in message news:341A3AF6-435E-49D2-AC4C-F3F972ECA1BC@microsoft.com... > Hello Ken, > > thanks to you I am now able to do what I wanted to do. > However.............there is always a but isn't there! > > Could you give me some pointers as to how to *move* a mail item from the > inbox to another folder based on the sender's name. I have seen another > thread about this but I confess I did not really understand the code > used/suggested. > Here I am 52 years old and only just learning a bit of VBA!! > > best regards > > Alastair
Create Macro to move email to subfolder in inbox
Start macro creating a mail with contact data and autotext Delegate Exporting Contacts using VBA? Copy message body with formatting from Outlook to Word. Inspector.WordEditor always returns null avoid syncing birthday date to calendar when saving contact Item Outlook confirmation dialog. Printing TIFF/JPG Attachment Show Sender Address in Tooltip or Customized View Redemption Error code 13 while opening addressbook - vbscript |
|||||||||||||||||||||||