| | | |

Fooling around with the Office Assistant

I seem to have a special bond with ancient stuff. I were doing Pascal when C++ and WinForm was at their prime. Now I’m toying with a discontinued Microsoft Office feature. I just can’t help it, I have to work with Office 2003 around the clock since the upper IT management takes about a decade to certify a new software as “compatible”. Well, working for a big corporation has its pros and cons and we all have to cope with them.

I don’t feel the Office assistant intrusive though, it certainly doesn’t get in your way if you turn it off, but oh well, only when you know how. (Which, sadly, is not the case for many computer users). And I don’t think we can just let the woman take it from us. Gdzie jest czcionka? 😉

[youtube=http://www.youtube.com/watch?v=VUawhjxLS2I&w=640&h=385]

When I was in 7th grade or something. I read an article on PCWorld Vietnam about how to manipulate the Office Assistant. I diligently typed the code (in VBA) character-by-character without even understanding them :P. Nevertheless, the result was really satisfying, I were able to make the cat  (Links, an office assistant character) jump through hoops (literally).

Okay, enough trivia! I don’t remember any function from back then so I’ll have to start over. I have done various applications inter-operating with Microsoft Office’s VBA before, so I guess it would be an easy task. I added the Microsoft Excel’s object library to my  C# project and search for “assistant”. Lucky me, something popped up.

Assistant class in object browser

As you may see, it’s a child of the application class so you’ll have to start an Office application first. I chose Excel because it’s the application I have been working with the most. For aesthetics reasons, I tried to hide the Application’s window but that will hide the assistant too :(.  Apart from that, thanks to the well-built COM interface, initialize and display the assistant is easy.

using Microsoft.Office.Interop.Excel;
...
ApplicationClass Test = new ApplicationClass();
Test.Assistant.On = true;
Test.Assistant.Visible = true;

In case you are wondering, ApplicationClass is used to control Excel. All the possible action of “Assistant” is neatly listed within an enum so I just have to convert those to text and list them for the user to choose. No button-to-button editing for each action required!

 foreach (string TypeName in Enum.GetNames(typeof(Microsoft.Office.Core.MsoAnimationType)))
 {
     listBox1.Items.Add(TypeName);
 }

Because you can only see the Office Assistant when the host Office application has focus, I made a timer so the assistant will do the same action over and over, so the user can switch to the relevant application.

        private void timer1_Tick(object sender, EventArgs e)
        {
            Microsoft.Office.Core.MsoAnimationType[] Temp = (Microsoft.Office.Core.MsoAnimationType[])Enum.GetValues(typeof(Microsoft.Office.Core.MsoAnimationType));
            if (listBox1.SelectedIndex >= 0)
            {
                Test.Assistant.Animation = Temp[listBox1.SelectedIndex];
                Test.Visible = true;
            }
        }

"Get techy" with Rocky :p

You can also make the assistant say stuff you want:

 private void button1_Click(object sender, EventArgs e)
 // I created a button and a TextBox
 // When you enter some text into the TextBox and click the button, the
 // assistant will make a speech balloon with the text in it
 {
   timer1.Enabled = false;
   MessageBox.Show("Switch to Excel after clicking OK");
   System.Threading.Thread.Sleep(2000);
   Microsoft.Office.Core.Balloon Speech = Test.Assistant.NewBalloon;
   Speech.Heading = "Test balloon";
   Speech.Text = textBox1.Text;

   Speech.Mode = Microsoft.Office.Core.MsoModeType.msoModeModal;
   Speech.Show();
   timer1.Enabled = true;
 }

Bark!

So if you are still stuck with Office 2003 and wanted to play around with it a bit, here’s the compiled application (requires .NET 2.0 and Microsoft Office 2003 installed) and for those who want the code, here it is.

Leave a Reply

Your email address will not be published. Required fields are marked *