7

I want to write a script (C# or AutoIT or VBScript.. whatever works) which should

  1. Get reference of already open outlook application

  2. Iterate through ribbons to find a specific button

  3. Execute that button click

How can I do it?

user4157124
  • 2,809
  • 13
  • 27
  • 42
helloworld
  • 2,179
  • 3
  • 24
  • 39
  • What does the button do? The same thing might be possible through the outlook COM or with an outlook plugin in C# – Matt Jul 06 '11 at 17:27
  • Button opens up a modal window with a textbox inside, which I want to focus. I've managed to get the button clicked with following code. Problem is my vbs scripts goes into a infinite wait after opening popup and Echo never executes. Set oShell = WScript.CreateObject("WScript.Shell") Set Outlook = WScript.CreateObject("Outlook.Application") oShell.AppActivate("Sent Items - Microsoft Outlook") Outlook.ActiveExplorer.CommandBars("MyControl").Controls(3).Execute() WScript.Echo("dd") – helloworld Jul 07 '11 at 13:44

1 Answers1

4

Use AutomationPeers.

Here is the MSDN article with lots of details: http://msdn.microsoft.com/en-us/library/ms752331.aspx

Add references to:

  • UIAutomationClient
  • UIAutomationClientsideProviders
  • UIAutomationProvider
  • UIAutomationTypes

And here is a little C# code snippet of how to get the AutomationId of what currently has focus:

var id = AutomationElement.FocusedElement.Current.AutomationId;
this.txt.Text = id;

You can navigate the entire tree of a window and drive the entire UI using automation peers. This is how accessibility applications interact with applications in Windows. This is also one way that automated UI testing applications do it as well.

justin.m.chase
  • 13,061
  • 8
  • 52
  • 100