-
Run code after item sent
I've created a userform that enables me to file an item from the Sent Items folder. The calling and initialise code is as follows
[VBA]
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Shows
End Sub
Sub Shows()
ufSentItems.Show
End Sub
Private Sub UserForm_Initialize()
Dim myOlApp As Outlook.Application
Dim myNamespace As NameSpace
Dim olItem As MailItem
Dim myFolder As Outlook.MAPIFolder
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
'get mail item from Sent Items folder
Set myFolder = _
myNamespace.GetDefaultFolder(5) 'Sent items folder
Set olItem = myFolder.Items(1)
Label1.Caption = olItem
Set myOlApp = Nothing
Set myNamespace = Nothing
Set myFolder = Nothing
Set olItem = Nothing
End Sub
[/VBA]
The problem appears to be that the userform is opened before the mail has reached the Sent Items folder, giving me an error on this line.
[VBA]
Set olItem = myFolder.Items(1)
[/VBA]Is there a way to delay things until the item arrives, or a different event I can use?
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules