I have an Outlook VBA script that is moving emails from one Exchange server to another.
After each mail is moved, the Outlook status bar starts displaying "Updating Account#Server.com" or "Updating Inbox". Eventually it displays "All folders are up to date."
Is there an Outlook VBA event associated with the end of this "Updating" process? I.e. is there an event that fires when it next displays "All folders are up to date"?
It seems to be independent of the Outlook Send & Receive process, for which the end is notified with this event: https://learn.microsoft.com/en-us/office/vba/api/outlook.syncobject.syncend
There is no other event for the sync complete action in Outlook.
The SyncObject allows users to synchronize Microsoft Outlook folders, address books, and folder home pages for offline use. The best what you can do is to subscribe to the SyncEnd event of each SyncObject instance.
Related
I am using the ItemAdd event to watch for new Outlook emails. Does this event work while the application is closed?
Currently, my macro launches upon initial startup using the "Application_Startup()" event, and then initializes a class module containing a sub routine that is trigged with the "ItemAdd" event. If I close Outlook, will this macro still be watching for a new "ItemAdd" event?
Thanks!
No, it will not - the event is fired by the application only, so no application - no event.
Keep in mind that if this is a cached profile, these events will fire on application startup when the cached mailbox (OST) is updated. You can also work around this by processing all unread emails on startup (assuming they stay unread). Or you can persist the MailItem.ReceivedTime property of your last processed message and process all emails newer than that on startup.
I have enabled the SupportsPinning in Manifest and also implemented event handler of ItemChanged. It works prefect until one of our users, pinned the taskPane and search email item with "All Mailboxes".
[Steps to reproduce]
Click any email item in Inbox
Activate the Addin
Pinned the Addin
Search something with "All mailBoxes"
Got some results which emails are locating in Archive MailBox
click to the email which it is located in Archive MailBox
ItemChanged event fired from last selected email
TaskPane looks like unload and reload
Office.Initialize will not be fired, but general JQuery could be fired.
None of the any Office API will be executed
Select other email which it is located in Inbox
no change on TaskPane, ItemChanged would fire
Addin only works normal if I close and re-activate the addin
After some searching and read carefully, I found that mail items in Archive Mailbox is not supported to activate the addin. If I click any email item outside of the "Search results", the addin button won't be available. But as of the Pinned feature, now we could have a way to be "activated" the addin from not supported mail item.
https://learn.microsoft.com/en-us/outlook/add-ins/#mailbox-items-available-to-add-ins
is there a way to "Force" disable the activation or "force" close the addin when user selected any "non-supported" email item?
I'm using Excel VBA to stage emails in Outlook and it is working well.
Dim template As Outlook.MailItem, tomerge As Outlook.MailItem
' Create E-mail
tomerge.Close olSave
The e-mails can then be manually moved to the Drafts folder and sent using this Sub.
'Loop through items in Drafts folder
objDrafts.Item(i).Send
However, many users have a bunch of extra drafts in their Drafts folder that they don't want sent.
If I replace "olFolderDrafts" with "olFolderOutbox" and try to send from their Outbox. The first message sends and then I get a "Run-time error" "Outlook has already begun transmitting this message".
Is there some way to send all from the Outbox or even better is there someway to stage and send from a newly created folder?
You need to create a folder for your unsent items and process them separately. As a rule the Outbox folder contains already submitted items. So, that's not a right place for your items.
The Outlook Object Model provides the Add function of the Folders class. You can get an instance of the Folders class using the Folders property of the Folder class in Outlook. You can read more about that in the How To: Create a new folder in Outlook article.
This answer was inspired by Nagarajan's comment above, but there are quite a few changes necessary from the answer in Send/Receive in Outlook Via Code. The main problem is using olSave doesn't put the messages in a "ready to send" state in Outlook so starting a sync using syc.Start from the answer above does nothing.
Instead, we found the following process to be straight forward:
Put Outlook in offline mode using "Send/Recieve" -> "Work Offline"
Use Excel VBA to stage the e-mails and instead of saving just .Send each email. As Outlook is offline they will be staged and ready to be sent but not actually sent.
The e-mails should now be staged in Outlook's Outbox folder and can be reviewed just be sure to press the "send" button after reviewing/editing messages otherwise the e-mail you modified will be removed from the queue.
When the messages are ready to be sent put Outlook back in online mode and they will be sent automatically.
I got an issue with the macro I did in Outlook. To resume, the macro starts every time I receive an email. Then it will run a few others Sub, modify an Excel file and so one. When Outlook is running and I receive a new email, everything works perfectly. The problem occurs when I open Outlook and I receive more than one email at the same time.
I suppose the macro doesn't have enough time to end what it's doing with the first email and already try to start again with the next one.
Is there a way to keep the next emails in suspend in order to run the macro for each email, each one has its turn ? Or maybe you have another solution ?
Thank you.
PS: I can provide the code but it's very long.
The problem occurs when I open Outlook and I receive more than one email at the same time.
The NewMailEx event of the Application class is fired once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item.
The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item.
Make sure VBA macros are enabled and allowed to run when Outlook is started. Check out the Trust Center settings in Outlook.
I have Outlook VBA code that reads all incoming mails.
This code uses the MailItem to go through each mail looking at sender, to, subject and for attachments.
The heart of the code uses the urn:schemas feature that does a sql query on the inbox.
Thus if a new mail arrives the process that fires looks at the whole inbox every time and not just that mail. (The inbox is kept tidy and items are moved when processed.)
The heart of the query looks like this:
Dim Filter as String
Filter = "urn:schemas:mailheader:subject like '%That report - %'"
Dim iMailMatch As Object
Set iMailMatch = Inbox.items.Find(Filter)
The problem is that (occasionally) when the machine is locked (not logged out), the macro will fire on a new mail event, but it won't find anything even though there are mails which match.
When I unlock the terminal and a new mail arrives - the process fires and it picks up/processes mails successfully that it previously didn't see.
The problem is only apparent when the terminal is locked. Thus I can only think that it has to do with kind of trust privileges.
There are times is does fire successfully when the terminal is locked, but it appears to be only when a mail arrives soon after the terminal is locked.
Do not search. NewMailEx event passes the entry id of the new item to your event handler - open the item using Namespace.GetItemFromID, then read the MailItem.Subject property.