简体   繁体   中英

get outlook to fire vba script on old emails

I have wrote some vba in outlook that fires when a new email comes in. However I want to fire it on an old email for testing. Can anyone tell me how.

my current code is

Private Sub objInbox_ItemAdd(ByVal Item As Object)

Thanks

I've sorted it thanks.

Private Sub Application_Startup()
   Set objInbox = Session.GetDefaultFolder(olFolderInbox).Items
'Call test
   'MsgBox "outlook starting"
End Sub
Sub test()
    MsgBox "in test"
    Dim ns As NameSpace
    Dim item As Object
    Dim inbox As MAPIFolder
     'Dim sub_folder As MAPIFolder

    Set ns = GetNamespace("MAPI")
    Set inbox = ns.GetDefaultFolder(olFolderInbox)
     'Set sub_folder = inbox.Folders("TEST")

    For Each item In inbox.Items
    If TypeOf item Is MailItem Then
        MsgBox "right subject"
    End If
    Next item
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM