Jump to content

VBA troubles


Recommended Posts

Hi,

I have taken a VBA script from the Microsoft website. I want to forward all my OL mails to a web account and the normal 'rules and alerts' wont do it - I think our IT guys have disabled it.

I had this in debug mode and when it fired - on arrival of a mail - i stepped through and it worked fine. I saved it and exited the VBA editor and recieved another mail but......nothing happened.

Any advice/guidance most appreciated - BTW total novice with VBA

cheers

Alastair

Code

----------------------------------------------------------------------------------------------------

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)

' 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 "forward@address"

' Send it

myForward.Send

End If

End Sub

Link to comment
Share on other sites

I have used VBA on Outlook before, but I have no idea why incoming mail does not trigger your script.

Perhaps a better place to ask for help is news://msnews.microsoft.com/microsoft.publ...per.outlook.vba - this is also available as a web interface; google for 'microsoft.public.office.developer.outlook.vba'.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy