PDA

View Full Version : Unwanted Outlook Windows



chrismc
11-27-2011, 08:30 AM
Hi everyone,

I've been using a couple of macros to automatically send emails with particular details completed for some time and they have worked fine.

A few months back after one of the Windows Updates I started to get additional windows opening up in Outlook although I hadn't actually changed the coding. This isn't a big problem when I'm only sending a couple of emails but some some pieces of work the code works through 200 emails and so creates 400 unwanted Windows.

I use Outlook 2007 with Exchange server.

I've found that the code which triggers the new windows is:

olApp.GetNamespace("MAPI").Folders.GetFirst.GetExplorer.CommandBars.FindControl(, 5613).Execute

I use it once to set Outlook as offline and later to set Outlook as online. I've found it necessary to include this coding to ensure that Outlook delays doing stuff whilst the code is running. I'd checked out quite a few links from VBA Express to find a way to ensure code had time to run and this worked better for me than the application.wait approach.

Simplest solution?
As the windows which open are for folders that are parents of folders that items are being filed into it is possible to predict which windows will appear I suspect that I could add code to close the windows.

Could you please help with with code for:
- close a window using a hard coded window name
- close a window which is the parent of an identifiable folder
- anything better

Thanks in advance

Chris

chrismc
12-10-2011, 04:47 AM
Managed to find
windows.count
which seems to work for Excel and Word but not in Outlook.

monarchd
12-13-2011, 09:05 AM
I had a similar need to have Outlook wait until a file completely saved before trying to open it and print it. I used this function from Sergey Merzlikin, maybe that will help:

http://stackoverflow.com/questions/5016637/need-to-create-a-30-second-delay-in-visual-basic

monarchd
12-13-2011, 09:08 AM
Oh, then basically in my code where I want it to wait, I put this line in with the amount of time I want it to wait in milliseconds:


'wait for it
MsgWaitObj 2000

chrismc
12-13-2011, 12:41 PM
Thanks monarchd. I've found some references to dealing with windows which I'll post about later. I've had a quick look at the link you gave and I see that it is for VB6. Is this directly transferrable to VBA?

Cheers.

monarchd
12-13-2011, 01:21 PM
By directly transferrable, I think that's a yes. If I recall, I just copied/pasted the code in my Outlook Module and then used it within my existing code. I even call the MsgWaitObj within my loop so that it pauses as it goes thru the attachments on my messages in the Inbox (which it saves the attachment to C:\, waits 2 seconds, opens the file, and then prints it).