Auto Forward Emails - Specific Time Periods Only

J

J_Nettles

Afternoon All:

I'm not sure if this can be done or not... we want to auto forward by rule
email messages during a specific time period... most specifically after
hours... is it possible to create a rule that would forward emails with a
specific criteria during a specific set of hours?

Thanks
 
J

Josh Skelton

Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.

To use it:
1. Start Outlook
2. Click Tools->Macro->Visual Basic Editor
3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"
4. Copy the script below
5. Paste the script into the right-hand pane of the VB Editor
6. Edit the script making the changes as per the comments I included in the code
7. Click the diskette icon on the toolbar to save the changes
8. Close the VB Editor
9. Click Tools->Macro->Security
10. Set Security Level to Medium
11. Close Outlook
12. Start Outlook
13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.
14. Test the macro
15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.
16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.
17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.

'START CODE
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate Items collections for folders we want to monitor
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub Application_Quit()
' disassociate global objects declared WithEvents
Set objInboxItems = Nothing
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim olItems As Items, _
olItem As Object, _
olMailItem As MailItem, _
olAttachmentItem As Attachment, _
bolTimeMatch As Boolean
Set olItems = objInboxItems.Restrict("[Unread] = True")
For Each olItem In olItems
If olItem.Class = olMail Then
Set olMailItem = olItem
'Change the times on the next line to those you want to use
bolTimeMatch = (Time >= #4:00:00 PM#) And (Time <= #8:30:00 AM#)
If bolTimeMatch Then
Dim objMail As Outlook.MailItem
Set objItem = olMailItem
Set objMail = objItem.Forward
'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE
objMail.To = "(e-mail address removed)"
objMail.Send
Set objItem = Nothing
Set objMail = Nothing
End If
End If
Next
End Sub

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
'END CODE
 
J

Josh Skelton

Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.

To use it:
1. Start Outlook
2. Click Tools->Macro->Visual Basic Editor
3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"
4. Copy the script below
5. Paste the script into the right-hand pane of the VB Editor
6. Edit the script making the changes as per the comments I included in the code
7. Click the diskette icon on the toolbar to save the changes
8. Close the VB Editor
9. Click Tools->Macro->Security
10. Set Security Level to Medium
11. Close Outlook
12. Start Outlook
13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.
14. Test the macro
15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.
16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.
17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.

'START CODE
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate Items collections for folders we want to monitor
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub Application_Quit()
' disassociate global objects declared WithEvents
Set objInboxItems = Nothing
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim olItems As Items, _
olItem As Object, _
olMailItem As MailItem, _
olAttachmentItem As Attachment, _
bolTimeMatch As Boolean
Set olItems = objInboxItems.Restrict("[Unread] = True")
For Each olItem In olItems
If olItem.Class = olMail Then
Set olMailItem = olItem
'Change the times on the next line to those you want to use
bolTimeMatch = (Time >= #4:00:00 PM#) And (Time <= #8:30:00 AM#)
If bolTimeMatch Then
Dim objMail As Outlook.MailItem
Set objItem = olMailItem
Set objMail = objItem.Forward
'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE
objMail.To = "(e-mail address removed)"
objMail.Send
Set objItem = Nothing
Set objMail = Nothing
End If
End If
Next
End Sub

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
'END CODE
Afternoon All:

I am not sure if this can be done or not... we want to auto forward by rule
email messages during a specific time period... most specifically after
hours... is it possible to create a rule that would forward emails with a
specific criteria during a specific set of hours?

Thanks
--
J_Nettles
On Tuesday, March 08, 2011 4:19 PM Josh Skelton wrote:
Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.



To use it:

1. Start Outlook

2. Click Tools->Macro->Visual Basic Editor

3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"

4. Copy the script below

5. Paste the script into the right-hand pane of the VB Editor

6. Edit the script making the changes as per the comments I included in the code

7. Click the diskette icon on the toolbar to save the changes

8. Close the VB Editor

9. Click Tools->Macro->Security

10. Set Security Level to Medium

11. Close Outlook

12. Start Outlook

13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.

14. Test the macro

15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.

16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.

17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.



'START CODE

Private WithEvents objInboxItems As Items



Private Sub Application_Startup()

Dim objNS As NameSpace

Set objNS = Application.GetNamespace("MAPI")

' instantiate Items collections for folders we want to monitor

Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Set objNS = Nothing

End Sub



Private Sub Application_Quit()

' disassociate global objects declared WithEvents

Set objInboxItems = Nothing

End Sub



Private Sub objInboxItems_ItemAdd(ByVal Item As Object)

Dim olItems As Items, _

olItem As Object, _

olMailItem As MailItem, _

olAttachmentItem As Attachment, _

bolTimeMatch As Boolean

Set olItems = objInboxItems.Restrict("[Unread] = True")

For Each olItem In olItems

If olItem.Class = olMail Then

Set olMailItem = olItem

'Change the times on the next line to those you want to use

bolTimeMatch = (Time >= #4:00:00 PM#) And (Time <= #8:30:00 AM#)

If bolTimeMatch Then

Dim objMail As Outlook.MailItem

Set objItem = olMailItem

Set objMail = objItem.Forward

'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE

objMail.To = "(e-mail address removed)"

objMail.Send

Set objItem = Nothing

Set objMail = Nothing

End If

End If

Next

End Sub



Function IsNothing(Obj)

If TypeName(Obj) = "Nothing" Then

IsNothing = True

Else

IsNothing = False

End If

End Function

'END CODE
 
J

Josh Skelton

Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.

To use it:
1. Start Outlook
2. Click Tools->Macro->Visual Basic Editor
3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"
4. Copy the script below
5. Paste the script into the right-hand pane of the VB Editor
6. Edit the script making the changes as per the comments I included in the code
7. Click the diskette icon on the toolbar to save the changes
8. Close the VB Editor
9. Click Tools->Macro->Security
10. Set Security Level to Medium
11. Close Outlook
12. Start Outlook
13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.
14. Test the macro
15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.
16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.
17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.

'START CODE
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate Items collections for folders we want to monitor
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub Application_Quit()
' disassociate global objects declared WithEvents
Set objInboxItems = Nothing
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim olItems As Items, _
olItem As Object, _
olMailItem As MailItem, _
olAttachmentItem As Attachment, _
bolTimeMatch As Boolean
Set olItems = objInboxItems.Restrict("[Unread] = True")
For Each olItem In olItems
If olItem.Class = olMail Then
Set olMailItem = olItem
'Change the times on the next line to those you want to use
bolTimeMatch = (Time >= #4:00:00 PM#) And (Time <= #8:30:00 AM#)
If bolTimeMatch Then
Dim objMail As Outlook.MailItem
Set objItem = olMailItem
Set objMail = objItem.Forward
'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE
objMail.To = "(e-mail address removed)"
objMail.Send
Set objItem = Nothing
Set objMail = Nothing
End If
End If
Next
End Sub

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
'END CODE
Afternoon All:

I am not sure if this can be done or not... we want to auto forward by rule
email messages during a specific time period... most specifically after
hours... is it possible to create a rule that would forward emails with a
specific criteria during a specific set of hours?

Thanks
--
J_Nettles
On Tuesday, March 08, 2011 4:19 PM Josh Skelton wrote:
Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.



To use it:

1. Start Outlook

2. Click Tools->Macro->Visual Basic Editor

3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"

4. Copy the script below

5. Paste the script into the right-hand pane of the VB Editor

6. Edit the script making the changes as per the comments I included in the code

7. Click the diskette icon on the toolbar to save the changes

8. Close the VB Editor

9. Click Tools->Macro->Security

10. Set Security Level to Medium

11. Close Outlook

12. Start Outlook

13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.

14. Test the macro

15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.

16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.

17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.



'START CODE

Private WithEvents objInboxItems As Items



Private Sub Application_Startup()

Dim objNS As NameSpace

Set objNS = Application.GetNamespace("MAPI")

' instantiate Items collections for folders we want to monitor

Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Set objNS = Nothing

End Sub



Private Sub Application_Quit()

' disassociate global objects declared WithEvents

Set objInboxItems = Nothing

End Sub



Private Sub objInboxItems_ItemAdd(ByVal Item As Object)

Dim olItems As Items, _

olItem As Object, _

olMailItem As MailItem, _

olAttachmentItem As Attachment, _

bolTimeMatch As Boolean

Set olItems = objInboxItems.Restrict("[Unread] = True")

For Each olItem In olItems

If olItem.Class = olMail Then

Set olMailItem = olItem

'Change the times on the next line to those you want to use

bolTimeMatch = (Time >= #4:00:00 PM#) And (Time <= #8:30:00 AM#)

If bolTimeMatch Then

Dim objMail As Outlook.MailItem

Set objItem = olMailItem

Set objMail = objItem.Forward

'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE

objMail.To = "(e-mail address removed)"

objMail.Send

Set objItem = Nothing

Set objMail = Nothing

End If

End If

Next

End Sub



Function IsNothing(Obj)

If TypeName(Obj) = "Nothing" Then

IsNothing = True

Else

IsNothing = False

End If

End Function

'END CODE
On Tuesday, March 08, 2011 4:20 PM Josh Skelton wrote:
Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.



To use it:

1. Start Outlook

2. Click Tools->Macro->Visual Basic Editor

3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"

4. Copy the script below

5. Paste the script into the right-hand pane of the VB Editor

6. Edit the script making the changes as per the comments I included in the code

7. Click the diskette icon on the toolbar to save the changes

8. Close the VB Editor

9. Click Tools->Macro->Security

10. Set Security Level to Medium

11. Close Outlook

12. Start Outlook

13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.

14. Test the macro

15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.

16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.

17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.



'START CODE

Private WithEvents objInboxItems As Items



Private Sub Application_Startup()

Dim objNS As NameSpace

Set objNS = Application.GetNamespace("MAPI")

' instantiate Items collections for folders we want to monitor

Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Set objNS = Nothing

End Sub



Private Sub Application_Quit()

' disassociate global objects declared WithEvents

Set objInboxItems = Nothing

End Sub



Private Sub objInboxItems_ItemAdd(ByVal Item As Object)

Dim olItems As Items, _

olItem As Object, _

olMailItem As MailItem, _

olAttachmentItem As Attachment, _

bolTimeMatch As Boolean

Set olItems = objInboxItems.Restrict("[Unread] = True")

For Each olItem In olItems

If olItem.Class = olMail Then

Set olMailItem = olItem

'Change the times on the next line to those you want to use

bolTimeMatch = (Time >= #4:00:00 PM#) And (Time <= #8:30:00 AM#)

If bolTimeMatch Then

Dim objMail As Outlook.MailItem

Set objItem = olMailItem

Set objMail = objItem.Forward

'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE

objMail.To = "(e-mail address removed)"

objMail.Send

Set objItem = Nothing

Set objMail = Nothing

End If

End If

Next

End Sub



Function IsNothing(Obj)

If TypeName(Obj) = "Nothing" Then

IsNothing = True

Else

IsNothing = False

End If

End Function

'END CODE
 
G

Goobus

Do you even bother to check the dates of the posts you are replying to?
Typical HoopleHead EggHead.

Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.

To use it:
1. Start Outlook
2. Click Tools->Macro->Visual Basic Editor
3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"
4. Copy the script below
5. Paste the script into the right-hand pane of the VB Editor
6. Edit the script making the changes as per the comments I included in the code
7. Click the diskette icon on the toolbar to save the changes
8. Close the VB Editor
9. Click Tools->Macro->Security
10. Set Security Level to Medium
11. Close Outlook
12. Start Outlook
13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.
14. Test the macro
15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.
16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.
17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.

'START CODE
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate Items collections for folders we want to monitor
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub Application_Quit()
' disassociate global objects declared WithEvents
Set objInboxItems = Nothing
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim olItems As Items, _
olItem As Object, _
olMailItem As MailItem, _
olAttachmentItem As Attachment, _
bolTimeMatch As Boolean
Set olItems = objInboxItems.Restrict("[Unread] = True")
For Each olItem In olItems
If olItem.Class = olMail Then
Set olMailItem = olItem
'Change the times on the next line to those you want to use
bolTimeMatch = (Time>= #4:00:00 PM#) And (Time<= #8:30:00 AM#)
If bolTimeMatch Then
Dim objMail As Outlook.MailItem
Set objItem = olMailItem
Set objMail = objItem.Forward
'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE
objMail.To = "(e-mail address removed)"
objMail.Send
Set objItem = Nothing
Set objMail = Nothing
End If
End If
Next
End Sub

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
'END CODE
Afternoon All:

I am not sure if this can be done or not... we want to auto forward by rule
email messages during a specific time period... most specifically after
hours... is it possible to create a rule that would forward emails with a
specific criteria during a specific set of hours?

Thanks
--
J_Nettles
On Tuesday, March 08, 2011 4:19 PM Josh Skelton wrote:
Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.



To use it:

1. Start Outlook

2. Click Tools->Macro->Visual Basic Editor

3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"

4. Copy the script below

5. Paste the script into the right-hand pane of the VB Editor

6. Edit the script making the changes as per the comments I included in the code

7. Click the diskette icon on the toolbar to save the changes

8. Close the VB Editor

9. Click Tools->Macro->Security

10. Set Security Level to Medium

11. Close Outlook

12. Start Outlook

13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.

14. Test the macro

15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.

16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.

17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.



'START CODE

Private WithEvents objInboxItems As Items



Private Sub Application_Startup()

Dim objNS As NameSpace

Set objNS = Application.GetNamespace("MAPI")

' instantiate Items collections for folders we want to monitor

Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Set objNS = Nothing

End Sub



Private Sub Application_Quit()

' disassociate global objects declared WithEvents

Set objInboxItems = Nothing

End Sub



Private Sub objInboxItems_ItemAdd(ByVal Item As Object)

Dim olItems As Items, _

olItem As Object, _

olMailItem As MailItem, _

olAttachmentItem As Attachment, _

bolTimeMatch As Boolean

Set olItems = objInboxItems.Restrict("[Unread] = True")

For Each olItem In olItems

If olItem.Class = olMail Then

Set olMailItem = olItem

'Change the times on the next line to those you want to use

bolTimeMatch = (Time>= #4:00:00 PM#) And (Time<= #8:30:00 AM#)

If bolTimeMatch Then

Dim objMail As Outlook.MailItem

Set objItem = olMailItem

Set objMail = objItem.Forward

'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE

objMail.To = "(e-mail address removed)"

objMail.Send

Set objItem = Nothing

Set objMail = Nothing

End If

End If

Next

End Sub



Function IsNothing(Obj)

If TypeName(Obj) = "Nothing" Then

IsNothing = True

Else

IsNothing = False

End If

End Function

'END CODE
On Tuesday, March 08, 2011 4:20 PM Josh Skelton wrote:
Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.



To use it:

1. Start Outlook

2. Click Tools->Macro->Visual Basic Editor

3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"

4. Copy the script below

5. Paste the script into the right-hand pane of the VB Editor

6. Edit the script making the changes as per the comments I included in the code

7. Click the diskette icon on the toolbar to save the changes

8. Close the VB Editor

9. Click Tools->Macro->Security

10. Set Security Level to Medium

11. Close Outlook

12. Start Outlook

13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.

14. Test the macro

15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.

16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.

17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.



'START CODE

Private WithEvents objInboxItems As Items



Private Sub Application_Startup()

Dim objNS As NameSpace

Set objNS = Application.GetNamespace("MAPI")

' instantiate Items collections for folders we want to monitor

Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Set objNS = Nothing

End Sub



Private Sub Application_Quit()

' disassociate global objects declared WithEvents

Set objInboxItems = Nothing

End Sub



Private Sub objInboxItems_ItemAdd(ByVal Item As Object)

Dim olItems As Items, _

olItem As Object, _

olMailItem As MailItem, _

olAttachmentItem As Attachment, _

bolTimeMatch As Boolean

Set olItems = objInboxItems.Restrict("[Unread] = True")

For Each olItem In olItems

If olItem.Class = olMail Then

Set olMailItem = olItem

'Change the times on the next line to those you want to use

bolTimeMatch = (Time>= #4:00:00 PM#) And (Time<= #8:30:00 AM#)

If bolTimeMatch Then

Dim objMail As Outlook.MailItem

Set objItem = olMailItem

Set objMail = objItem.Forward

'PUT THE EXTERNAL EMAIL ADDRESS YOU WANT TO USE ON THE NEXT LINE

objMail.To = "(e-mail address removed)"

objMail.Send

Set objItem = Nothing

Set objMail = Nothing

End If

End If

Next

End Sub



Function IsNothing(Obj)

If TypeName(Obj) = "Nothing" Then

IsNothing = True

Else

IsNothing = False

End If

End Function

'END CODE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top