Outlook Macro Executes even when deleted - vba

I can usually find an answer by searching the forum and applying my own answer but this has me stumped.
I have some vba in ThisOutlookSession that when a mail item is sent from a shared mailbox it moves that item into the sent items of the shared mailbox rather than the individuals. This has been working fine for roughly about a year...
For some reason in the last two weeks or so it has suddenly started to put two copies of the message into the shared mailbox sent items.
Whilst investigating this I noticed something, I entered a Stop line at the start of my code to allow me to step through it. The code fires, hits the Stop line and Stops as it should, however the item has already moved into the shared mailbox... I then step through the rest of the code and it moves the item again...
This is already strange, but what really got me is I have now deleted the code from the session (all of it nothing left), closed Outlook and rebooted the PC. I then sent a test message and guess what - its once again moved into to the shared mailbox sent items.
I haven't got any rules set up, so it cant be that... I only use ThisOutlookSession in Outlook, so its not firing from another Module
It's as though my script still exists in the background but I am unable to see it.
So my questions are:
1) has anyone else experienced this?
2) how is it possible for code to excecute when it doesn't exist (surely this is the equivalent of a human walking around without a head??)
3) does anyone have any solutions on how to resolve this?
I really hope someone out there can help because this has me completely stumped!
TIA

Related

Skip meeting request in for each selection loop

I am working on a simple Marco that use to download selected emails' attachments.
It was really a simple logic but I am still stuck.
I found out that my for each loop is always stop when it met the meeting request email.
(It almost took my whole day to figure it out that the meeting request is The Barricade.)
The problem can be fixed by deletion of the meeting request.
And yet, it is really annoying for a lazybones like me.
Therefore, I really curious that is there any method can let the for each loop just ignore/auto unselect meeting requests?
And I have already tried detect the email subject/context to seprate the meeting requests and normal mails.
But it seem like it would just exit the for each loop when it encountered the meeting request.
So currently I don't have any idea about how to fixing it.
Firstly, you need to show the relevant snippet of your code.
Secondly, you should not assume that you are only dealing with the MailItem objects - before accessing an of the MailItem-specific properties, check that the Class property (it is exposed by all OOM objects) is 43 (which is olMail).

Outlook VBA Autosave Attachments Rule - Downloadstate is zero?

I have a rule which starts a sub in VBA when a new eMail arrives.
The code automatically saves the attachment of the Mail in a specific folder.
This worked fine, as long as..... I reinstalled the system.
I added everything like it was, but now I'm suffering the following problem:
When the rule hits in, the eMail Object always has zero attachments. I was sniffing around a little bit and found out, that the Downloadstate is still zero (header only) when the sub runs.
On the web we can see lots of code snippets around for this functionality but Downloadstate seems never to be a topic. So it wasn't for me in the past!
What is wrong here? Why is the Downloadstate zero when the VBA Sub starts?
I found a little workaround by querying the downloadstate and re-run the procedure again with the same mail item. This loop works fine. Almost on the next run it seems that the message is fully downloaded already... And the procedure takes place like it should. But as i know that it worked fine right before, I just want to get rid of this again...
Can anybody help?

Outlook code stopped working

I have a 1-min delay on all emails and want to assign a category set up as an exception to the rule to send immediately.
I created the macro but it stopped working.
Public Sub CategoriesButton()
Dim Item As Outlook.MailItem
Set Item = Application.ActiveInspector.CurrentItem
Item.Categories = "SendMe"
Item.Save
End Sub
Interesting - I just had the same issue. Working perfectly but then I restarted Outlook and it stopped working - for no apparent reason.
Took me a while to work this out - but when you restart Outlook it applies Macro security permissions to your macro.
If you haven't digitally signed your macro, the default behaviour is to prevent it from running.
You can relax the security settings so that Outlook with either ask your permission to run macros, or just run all macros regardless (this latter option is probably not a good idea!)
You can self-sign your own macro, there's quite a good guide to doing that here: http://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/
But annoyingly it seems you will always get a notification, even with a signed macro... so it's probably easier to just change the security settings to 'notification for all'.
Hope this helps - the code you posted certainly helped me, it was exactly what I was looking for, also to control 1 minute delay!
Man, every time I go near macros in Outlook I end up losing half a day or so...

Compiling and Calling Code at Runtime

The other day, I took up a little bit of a project: creating an IRC bot. Currently, it works (with a few bugs that I know about and am working towards fixing), but there is one feature that I would like to implement. External modules.
Basically, what I am wanting is to have the end user be able to write their own Sub and have that checked when a message arrives.
Each sub that is checked starts off something like this:
Sub sampleSub(message As String)
What calls that bit of code is (another) sub that is run through when a message arrives. In short, when a message arrives, the following code is executed:
sampleSub(message)
(where message = the incoming message to be processed)
Is there a way to check a folder (say, /modules) for all .vb files, compile said files to .dll, and add those to a list of subs above to be checked?
(If you don't understand what I'm meaning about the above code, see https://github.com/xeon927/IRCBot/blob/master/main.vb lines 213, and 337-348)

Item is not added into the list (from code)

We have some strange problem here. We have feature event receiver, where we are creating custom fields -> content type -> list. After that, one default item is added. On my VM it was working just fine, but after moving into pre-prod environment, we got this strange behavior with no exception or error in logs.
First thing, item was created only sometimes, with no trace what happened. Mostly it was not created. I even experienced this: when I activated feature, I went to the list and so item there, but after refresh it was gone!
We tried to put there some Thread.Sleep() cycle (while debugging, item was in Items collection, but ItemsCount property of the list was always showing 0).
Now I am out of ideas what is wrong. It's not about execution time (maybe). Looks like, for some reason, SP is killing SPItem.Update before it is created for real and we don't know why. Any help is really welcome!
When you try to access sharepoint items from code and not have admin permissions to update/ delete them then set website website.AllowUnsafeUpdates = true; property
//Set AllowUnsafeUpdates = true to update the database / sharepoint list from code.
FormWeb.AllowUnsafeUpdates = true;
NewItem.Update();
FormWeb.AllowUnsafeUpdates = false;
you code should be like this to make changes in the list.. when you adding item to list.
Use Update statement in same manner when you accessing list and updating its data.
Check whether you updating the list correctly.. There may be some SharePoint security issue.
Reference Link:
http://blogs.msdn.com/b/infopath/archive/2010/04/01/add-items-to-a-sharepoint-list-using-managed-code.aspx.
You can check this [SPSecurity.RunWithElevatedPrivileges][1]
[1]: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx , link, link
you can check that what is going over there by adding your events in sharepoint..
Check this post and debug it..
http://developmentsolutionsjunction.blogspot.com/2011/06/adding-events-and-eventhandlers-in.html
so I was finally able to find out where the problem was. After deeper study and trying that and this I found out that there was a third party feature. It was adding event to each created list and was deleting everything what wasn't consistent with CT defined by company. This is weird and I don't really understand why somebody wants this. But ok, they pay, their rules.
So if you encounter such problem, try also this possibility.
However, I also leard few things during this, e.g. if you are working with SP instances from web scope, use web scoped features, not site ones, also, SP has a nasty habit to silent som exceptions. Also, if you e.g. take instance of SPWeb from event properties, it doesn't necessarily means it is already created. It takes some time, also, Update() itself is a thing that DB has to perform. Sometimes it's better to alsways check if you really have instance and if not, threadsleep for a while.
Have you used .Update() method in your code??