WithEvents not working

Status
Not open for further replies.

foncesa

Member
Outlook version
Outlook 2013 32 bit
Email Account
IMAP
Hi,

If someone could figure out what's wrong with the below WithEvents that it does not fire with new email.

Code:
Private WithEvents Items As Outlook.Items 
 
Private Sub Application_Startup()
   Dim appOl As Outlook.Application
   Dim ns As Outlook.NameSpace
   Set appOl = Outlook.Application
   Set ns = appOl.GetNamespace("MAPI")
   Set Items = ns.GetDefaultFolder(olFolderInbox).Folders("Personal Mail").Items 
 
End Sub 
 
Private Sub Items_ItemAdd(ByVal item As Object) 
 
On Error GoTo GetAttachments_err
   Dim appOl As New Outlook.Application
   Dim ns As Outlook.NameSpace
   Dim Inbox As Outlook.MAPIFolder
   Dim myDestFolder As Outlook.MAPIFolder
   Dim item As Object
   Dim Atmt As Outlook.Attachment
   Dim FileName As String
   Dim i As Integer
   Dim iLoop As Integer
   Dim Items As Outlook.Items
   Dim moveEmail As Boolean
   Set ns = appOl.GetNamespace("MAPI")
   Set Inbox = ns.GetDefaultFolder(olFolderInbox)
   Set item = Inbox.Items
   Set myDestFolder = Inbox.Folders("Personal Mail")
 
Is macro security set to low?

Did you click in Application_start up and click the Run button?

Is the mail being moved to this folder - the code only works on mail as its dropped into the folder. Test it by removing folders("personal mail") from the code and see if it works.

Set Items = ns.GetDefaultFolder(olFolderInbox).Folders("Personal Mail").Items
 
Thanks for response.

Is macro security set to low? Outlook 2013 Enable all Macros (option selected)

Did you click in Application_start up and click the Run button? Yes it runs properly from Private Sub Application_Startup()..... End Sub
But it does not call the Private Sub Items_ItemAdd(ByVal item As Object) the script which will get the attachments, thats where something is wrong?

Set Items = ns.GetDefaultFolder(olFolderInbox).Folders("Personal Mail").Items Tried with this option also.

I feel the WithEvents is wroking perfectly the only part the script is not called automatically.

Please suggest, help.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
R Class Modules and WithEvents Outlook VBA and Custom Forms 2
M Create email from Access on Outlook and make sure that email has beensent using WithEvents method Outlook VBA and Custom Forms 3
T Outlook 365 won't take new working password Using Outlook 0
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
Z Outlook 2021 Outlook new emails notification not working Using Outlook 4
A Outlook 365 Outlook (part of 365) now working offline - argh Using Outlook 5
G LinkedIn tab missing in Outlook 365 (but working in OWA) Using Outlook 0
BartH VBA no longer working in Outlook Outlook VBA and Custom Forms 1
S New Email "From" box stopped working Using Outlook 0
R Outlook Working off line Using Outlook 0
H How to Fix 1510-370-1986 Garmin GPS Not Working Outlook VBA and Custom Forms 0
M Outlook 2019 Macro not working Outlook VBA and Custom Forms 0
L Outlook 365 Outlook not working on linux how to solve it Using Outlook.com accounts in Outlook 0
Z Outlook.com OST Stopped working without explanation Using Outlook.com accounts in Outlook 3
Commodore Automatic switch between working offline/online Using Outlook 4
V Outlook 2016 iCloud for Windows - Why no working Calendars and Tasks ? Using Outlook 1
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
V Auto-complete stopped working Using Outlook 4
F Searches are not working properly Using Outlook 1
Jennifer Murphy Spam filter not working Using Outlook 13
D Connecting Gmail to Outlook 365 - My Setup not working Using Outlook 2
A Prepending Email Addrs with "Display Name <email>" Has Stopped Working Using Outlook 0
R rules not working - done troubleshooting Using Outlook 0
R Follow up button doesn't working neither the reminders in BCM BCM (Business Contact Manager) 0
A calendar invites sent from Microsoft Outlook to Mac Outlook is not working Using Outlook 2
Z Task Filter Not Working When I add too many criteria Using Outlook 0
D iCloud Add-in not working in Outlook 2013 and Outlook 2016 After Windows Upgrade & iCloud Upgrade Using Outlook 2
bmtjedi Set objApp = Application Not Working in O365-32bit Using Outlook 1
B Outlook 2003 email sending & receiving suddenly stopped working Using Outlook 3
S Outlook Custom Form Scripting only working when clicking on "Run this form" Outlook VBA and Custom Forms 2
K Outlook 2016 - controlling IMAP OST size with Group Policy not working Using Outlook 1
F KB4475563 stops VBS at forms working Outlook VBA and Custom Forms 3
J Copy to calendar function no longer working in outlook 365 Using Outlook 5
D Archive by receive date not working Using Outlook 2
M move to iCloud not working in outlook calendar Using Outlook 12
cricket1001 Shade non-working days in calendar Using Outlook 0
L Outlook 2019 MAC sync error after working for 4 hours Using Outlook 1
A rules not working Using Outlook 2
B Reply and replyall macro is not working Outlook VBA and Custom Forms 1
D Any updates or fixes that would make this code stop working just moving emails to another folder Outlook VBA and Custom Forms 1
V Autocomplete not working on new email account Using Outlook 4
P Two main Outlook gripes: Voting buttons not working externally nor Focused Inbox Using Outlook 1
M email search not working Using Outlook 1
B When working on emails in a certain folder, when I hit reply or reply all, I would like it re always reply all and add an email address to send to Outlook VBA and Custom Forms 3
J Menus not working BCM (Business Contact Manager) 7
K Working with Explorer.Close event Outlook VBA and Custom Forms 3
N Syncing my inbox not working for certain types of mail Using Outlook 9
A rules (flags) not working Using Outlook 7
P Outlook search is not working at all for Calendar & Tasks Using Outlook 7

Similar threads

Back
Top