Beginner Needs VBA Help in Modifying Code

Status
Not open for further replies.
C

Cody

I am using Outlook 2003 and want to do the following:

Email received between 6 pm to 9 am is forwarded to zyx@123.lyz

Email received between Friday @ 6pm to Monday @ 9 am is forwarded to

zyx@123.lyz

Email received between 9am to 6pm is forwarded to abc@123.lyz

I have looked on the web and found the following code on the MS website; but

unfortunately I am not sure where I am suppose to modify it. If you can

give me any guidance, I would appreciate it.

********

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.

Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items

End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)

' If it's currently not between 9:00 A.M. and 5:00 P.M.

If Time() < #9:00:00 AM# Or Time() > #5:00:00 PM# Then

' 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 "myaddress@mydomain.com"

' Send it

myForward.Send

End If

End If

End Sub

********

Thanks...Cody
 
J

JP

I responded to this exact question yesterday, see

http://groups.google.com/group/micr.../browse_thread/thread/f4f24cb355cac433?hl=en#

--JP

On Sep 24, 12:54 pm, Cody <C...> wrote:
> I am using Outlook 2003 and want to do the following:

> Email received between 6 pm to 9 am is forwarded to z...@123.lyz
> Email received between Friday @ 6pm to Monday @ 9 am is forwarded to
> z...@123.lyz
> Email received between 9am to 6pm is forwarded to a...@123.lyz

> I have looked on the web and found the following code on the MS website; but
> unfortunately I am not sure where I am suppose to modify it.   If you can
> give me any guidance, I would appreciate it.

> ********

> 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.
>    Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items

> End Sub

> Private Sub myOlItems_ItemAdd(ByVal Item As Object)

>    ' If it's currently not between 9:00 A.M. and 5:00 P.M.
>    If Time() < #9:00:00 AM# Or Time() > #5:00:00 PM# Then

>       ' 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 "myaddr...@mydomain.com"

>          ' Send it
>          myForward.Send

>       End If

>    End If

> End Sub

> ********
> Thanks...Cody
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
There's already the code for items received between 5pm and 9am. If you want

to add another condition, you can use the ElseIf statement like this:

If ... Then

> ..

ElseIf ... Then

> ..

End If

Best regards

Michael Bauer

Am Thu, 24 Sep 2009 09:54:01 -0700 schrieb Cody:


> I am using Outlook 2003 and want to do the following:

> Email received between 6 pm to 9 am is forwarded to zyx@123.lyz
> Email received between Friday @ 6pm to Monday @ 9 am is forwarded to
> zyx@123.lyz
> Email received between 9am to 6pm is forwarded to abc@123.lyz

> I have looked on the web and found the following code on the MS website;


but
> unfortunately I am not sure where I am suppose to modify it. If you can
> give me any guidance, I would appreciate it.

> ********

> 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.
> Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items

> End Sub

> Private Sub myOlItems_ItemAdd(ByVal Item As Object)

> ' If it's currently not between 9:00 A.M. and 5:00 P.M.
> If Time() < #9:00:00 AM# Or Time() > #5:00:00 PM# Then

> ' 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 "myaddress@mydomain.com"

> ' Send it
> myForward.Send

> End If

> End If

> End Sub

> ********
> Thanks...Cody
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
N Beginner - Setting SMTP settings/travelling Using Outlook 4
S Exchange Server Beginner Questions Exchange Server Administration 2
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
C Newbie needs help with Outlook Macro Outlook VBA and Custom Forms 3
lotsbg Loads of junk in second email needs fixing Using Outlook 1
R Narcotics Police Officer Needs help Using Outlook 1
Y Changing colour of selection bar in Outlook (too light, needs to be grey) Using Outlook 4
J Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconve Using Outlook 2
D Outlook Form Needs to move P2 to the Task Pane Using Outlook 2
H Outlook 2010 reminder needs to pop up Using Outlook 1
B seting up office outlook...during set up, a box showed STMP POP3 for sending emails, the recieving box was empty. What information needs to go into t Using Outlook 2
K Microsoft office outlook has encountered a problem and needs to close. We are sorry for the inconven Using Outlook 3
G Scanpst.exe error but can't find file that needs to be fixed due to outlook not opening up Using Outlook 3
D Outlook 2010 Conversation Feature - Needs another option Using Outlook 1
T What permissions needs for booking room in exchange 2010 Exchange Server Administration 6
T Re: What permissions needs for booking room in exchange 2010 Exchange Server Administration 2
W Microsoft has encountered a problem and needs to close. Using Outlook 3
M office 2007 - office outlook has encountered a problem...needs to close Using Outlook 3
G Office Outlook has encountered a problem and needs to close. Using Outlook 1
N Re: Outlook needs account access permission to open but doesnt work right after that. Using Outlook 2
B Exchange 2010 High Availability needs a SAN ?? Exchange Server Administration 2
T Outllok 2007 needs to be restarted to receive email Using Outlook 5
J Newbie needs help Outlook VBA and Custom Forms 2
J To-do bar needs to show appointments from multiple calendars Outlook Wishlist 3
Forum Admin What needs fixing in Outlook? Outlook Wishlist 18
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
L VBA unknown character Outlook VBA and Custom Forms 2
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
K Use VBA to find Sender and Recipient from Microsfot 365 Journaled Email Items Outlook VBA and Custom Forms 3
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 2
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
C VBA to prompt for Sent folder destination Outlook VBA and Custom Forms 3
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D.Moore VBA script fail after Office 365 update Using Outlook 8
R Limiting length of saved attachment in VBA Outlook VBA and Custom Forms 2
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
C How to use VBA to show only items x days old or more Outlook VBA and Custom Forms 1
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
S Reference Custom Fields with VBA Outlook VBA and Custom Forms 2
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
G VBA Macro Calendar Printing Assistant 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
B VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
Similar threads


















































Top