Outlook VBA Script

Author Message
mrtanner87

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 11/18/2009
  • Status: offline
Outlook VBA Script Wednesday, November 18, 2009 12:05 PM (permalink)
0
Hi guys,

I found this script on the net, which is supposed to move any sent mail on behalf of someone from my sent box to the on behalf of persons sent box. However when I run it I get a debug error which I have no idea how to fix.. Would there be anyone out there who can help???

Private SentEntryID As String
Private SentStoreID As String
Private WithEvents objSentItems As Items
Private MailItem As Outlook.MailItem

Public Sub Application_Startup()
'Retrieve ID for accessing non-default sent folder
getStoreFolderID ("Mailbox – Finanz")
Set objSentItems = Application.Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Function getStoreFolderID(StoreName)
'Gets the Shared Account Sent Folder
Dim Store As Object
Dim StoreFolder As Object
Dim i As Integer
Set Store = Application.GetNamespace("mapi").Folders
For Each StoreFolder In Store
If StoreFolder.Name = StoreName Then
For i = 1 To StoreFolder.Folders.Count
If StoreFolder.Folders(i).Name = "Sent Items" Then
SentEntryID = StoreFolder.Folders(i).EntryID
SentStoreID = StoreFolder.Folders(i).StoreID
Exit For
End If
Next
Exit For
End If
Next
Set Store = Nothing
Set StoreFolder = Nothing
End Function

Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem = Application.GetNamespace("mapi").GetItemFromID(.EntryID, .Parent.StoreID)
End With
If MailItem.SentOnBehalfOfName = "Finanz" Then
Set DestinationFolder = Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub

Debug stops at the line in red with the error message " Could not open the item. Try Again"


Thanks for any help in advance


Mr Tanner
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:Outlook VBA Script Thursday, November 19, 2009 4:23 AM (permalink)
    0
    Just to be clear, this is VBA not VBScript code.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9