Greetings Bird,
Public WithEvents inbox As Outlook.Items
*-Compile error:
Only valid in object module-*
Where did you put the code.
I put the code to the Outlooks "ThisOutlookSession" class.
From outlook Tools/Macro/Visual Basic Editor
From the visual basic editor project tree view I select the ThisOutlookSession
Hope this helps some.
BR, Mani
"Bird" wrote:
Mr_Mani,
I have encountered some problems during the implementation your
original code, please see below. First problem was with the
ThisOutlookSession statement, and then just for laughs I
commented-out that code and had a problem with WithEvents. I would
appreciate any assistance you could give me on this. Again thank you,
Bird
Option Explicit
ThisOutlookSession
*-Compile error: Invalid outside
procedure-*
Public WithEvents inbox As Outlook.Items
*-Compile error:
Only valid in object module-*
Private Sub Application_MAPILogonComplete()
Set inbox =
GetNamespace("MAPI").GetDefaultFolder(olFolderInbo x).Items
Set inbox =
GetNamespace("MAPI").Folders("PersonalFolders").Fo lders("Inbox").Items
End Sub
Private Sub inbox_ItemAdd(ByVal Item As Object)
Dim mItem As MailItem
Dim sItem As Object
Dim objExcel As Object
If TypeName(Item) = "MailItem" Then
Set mItem = Item
If mItem.Subject = "JJJ" Then
mItem.Attachments.Item(1).SaveAsFile ("C:\Temp\" _
& mItem.Attachments.Item(1).DisplayName)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.WorkBooks.Open ("C:\Temp\" &
mItem.Attachments.Item(1).DisplayName)
End If
End If
End Sub
--
Bird
------------------------------------------------------------------------
Bird's Profile: http://www.excelforum.com/member.php...o&userid=24469
View this thread: http://www.excelforum.com/showthread...hreadid=505757