PDA

View Full Version : Outlook 2010 SendKeys



akribie
02-26-2017, 05:19 AM
Hi,

I have many email accounts in Outlook 2010 and am looking for a way to automate collapsing mail folders in the Folder pane which insist on opening whenever a new email arrives for that account. I use favourite folders to offset this problem, but it is still a pain to have many folders open each with many open sub-folders.

Starting with Personal Folders at the top of the list, repetitive manual keystrokes of LEFT and DOWN have the desired result.

However,, the equivalent macro:


Sub CollapseFolders()
Application.SendKeys "{LEFT}{DOWN}", True
Application.SendKeys "{LEFT}{DOWN}", True
End Sub


fails with "Object does not support this property or method", whereas these versions:


Sub CollapseFolders()
SendKeys "{LEFT}{DOWN}", True
SendKeys "{LEFT}{DOWN}", True
End Sub

Sub CollapseFolders()
SendKeys "{LEFT}{DOWN}"
SendKeys "{LEFT}{DOWN}"
End Sub



compile OK, but achieve nothing.

I am aware that many internet answers suggest this task is not automatable, but it isn't obvious to me why this code should not work.

Grateful for any hints or explanations as to why the MS documentation does not mention any relevant restrictions.

Thanks !

Paul_Hossler
02-26-2017, 08:04 PM
SendKeys is famous for being buggy

ON my PC



Sub CollapseFolders()
SendKeys "{LEFT}{DOWN}", True
SendKeys "{LEFT}{DOWN}", True
End Sub


just turns NumLock on and off (below)


https://support.microsoft.com/en-us/help/179987/bug-multiple-sendkeys-statement-turns-off-numlock-key



From the article, one GUESS might be to try something like this




Sub CollapseFolders()
SendKeys "{LEFT}", True
DoEvents
SendKeys "{DOWN}", True
DoEvents
SendKeys "{LEFT}", True
DoEvents
SendKeys "{DOWN}", True
DoEvents
End Sub