Need to know how to access Office Events to extend Office apps

J

j

Hi, I need a little direction to get me going.

What I'm wanting to do is for any Office application:
1. Capture a Menu click event
2. Capture that Menu's items (submenu)
3. Create a seperate window with those submenu items
4. Capture submenu item click on the new window
5. Send submenu item click event back to Office application's submenu

The target is Office 2000 and Office XP.

Is VBA the way to do this? Or can an app be written in C# or VB and used to
extend Office? If someone could point me in the right dorection. So far, I
cannot find clear instructions on how to extend Office in this way.

Thanks!
J
 
C

Chris Jensen [MSFT]

Hello J,

The easiest way to do all that you list is through a COM add-in. The COM
add-in applies to both Office 2000 and Office 2002 (XP). You can write one
in VB, VB .NET, C#, VC++, VBA and other COM-aware languages. There are
several Microsoft Knowledge Base articles that discuss the subject and give
you sample code. Here is a list of some of them that should help.

238228 HOWTO: Build an Office 2000 COM Add-In in Visual Basic
http://support.microsoft.com/?id=238228
( Look for the section that starts with the line
"Building a COM Add-In Using the VB6 Add-in Designer ")

306130 HOW TO: Create Office COM Add-Ins by Using VBA and Office Developer
http://support.microsoft.com/?id=306130

230689 SAMPLE: Comaddin.exe Office 2000 COM Add-In Written in Visual C++
http://support.microsoft.com/?id=230689

If you are using Excel 2000 this article discusses how to call a method of
a COM add-in from Excel
256624 HOWTO: Use a COM Add-In Function as an Excel Worksheet Function
http://support.microsoft.com/?id=256624

316983 OL: A Sample COM Add-in That Uses the Visual Basic 6.0 Add-in
Template
http://support.microsoft.com/?id=316983
(this is particular to building a COM Add-in for Outlook)

302896 HOW TO: Build an Office COM Add-in by Using Visual Basic .NET
http://support.microsoft.com/?id=302896

302901 HOW TO: Build an Office COM Add-in by Using Visual C# .NET
http://support.microsoft.com/?id=302901

325668 XL2002: Issues Fixed in Excel 2002 by Office XP Service Pack 2
http://support.microsoft.com/?id=325668

322027 OL2002: COM Add-Ins Are Not Trusted If They Are Created with Visual
http://support.microsoft.com/?id=322027

327657 OL2002: How to Create Trusted Outlook COM Add-Ins
http://support.microsoft.com/?id=327657

Other articles that may prove useful to you include:

316723 PRB: Visual Studio .NET Shared Add-in Is Not Displayed in Office COM
http://support.microsoft.com/?id=316723

316724 PRB: Macro Warning Occurs in an Office Application When You Load a
.NET
http://support.microsoft.com/?id=316724

253338 INFO: Office Developer Samples and Tools Available for Download
http://support.microsoft.com/?id=253338

The next two articles are about "Automation Add-ins". Those are new with
Excel 2002. With those, Excel can call the functions of the Add-in
directly. However, there are other aspects of an automation add-in that you
may consider impractical when you consider your end-user needs. Please make
your own evaluation.

291392 INFO: Excel COM Add-ins and Automation Add-ins
http://support.microsoft.com/?id=291392

285337 HOWTO: Create a Visual Basic Automation Add-in for Excel 2002
Worksheet
http://support.microsoft.com/?id=285337

More information:

When you say you want to create a separate window you're probably going to
add a Windows form that is created by a menu item. The following
information is deals with a problem using a modeless form, and suggests a
workaround for the problem:

Modeless Windows Form in an Office COM Addin Ignores Keystrokes
----------------------------------------------------------------------------
---
This information applies to:

- Microsoft Excel 2002
- Microsoft Word 2002
- Microsoft PowerPoint 2002
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# .NET (2003)

----------------------------------------------------------------------------
---

SYMPTOMS
========

You have used Visual Basic .NET or Visual Basic C# to create an Office COM
Addin that displays a modeless Windows Form. When the form has focus,
keystrokes are ignored. This includes the Tab key for cycling between
controls on the form and accelerator keys for controls on the form.

WORKAROUND
==========

To workaround this problem, show the form as a modal dialog using the
ShowDialog method. To achieve functionality similar to a modeless form,
you can show the form modal on a different thread as illustrated below.

1. Follow the steps in the following article to build a basic COM
Addin: KBLink:302896.KB.EN-US: HOW TO: Build an Office COM Add-in by
Using Visual Basic .NET
2. On the Project menu, choose Add Windows Form. Select the Windows
Form template and click Open.
3. Add two Button controls to Form1.
4. In connect.vb, replace the code in MyButton_Click with:

Dim frm As New Form1()
frm.Show()
5. On the Build menu, choose Build Solution.
6. Start Excel and click the custom commandbar button that the COM
Addin creates.
7. When Form1 appears, press Tab to cycle the two buttons. Notice that
the Tab key is not recognized by the form.
8. Close the form and quit Excel.
9. To workaround this problem so the Tab keys (and other keys) are
recognized by the Windows Form:
a. Add a new class to the Form1 class:

Public Class MyThread
Public Sub MyThreadProc()
Dim frm As New Form1()
frm.ShowDialog()
End Sub
End Class
b. Replace the code in MyButton_Click with:

Dim oTHandler As MyThread = New MyThread()
Dim oStart As System.Threading.ThreadStart = New
System.Threading.ThreadStart(AddressOf oTHandler.MyThreadProc)
Dim oT As System.Threading.Thread = New System.Threading.Thread(oStart)
oT.Start()
c. On the Build menu, choose Build Solution.
d. Start Excel and test the Form again. Now, pressing the Tab key will
cycle the controls on the form as expected.

A Modal form won't have a menu, but you can use Command Buttons to provide
the same functionality. Or, you can use VB 6.0 to build the Add-on and in
that use a Modeless form.

Best wishes for the success of your project.


--------------------
From: "j" <[email protected]>
Subject: Need to know how to access Office Events to extend Office apps
Date: Tue, 1 Jul 2003 09:41:07 -0400
Hi, I need a little direction to get me going.

What I'm wanting to do is for any Office application:
1. Capture a Menu click event
2. Capture that Menu's items (submenu)
3. Create a seperate window with those submenu items
4. Capture submenu item click on the new window
5. Send submenu item click event back to Office application's submenu

The target is Office 2000 and Office XP.

Is VBA the way to do this? Or can an app be written in C# or VB and used to
extend Office? If someone could point me in the right dorection. So far, I
cannot find clear instructions on how to extend Office in this way.

Regards,
Chris Jensen[MSFT]

This posting is provided “AS IS” with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
<http://www.microsoft.com/security>.
 
J

j

Hi Chris,

Thanks for all the info! This is great! I am glad to know I can use C# and
do not need to use VBA. The add-in I am creating will be used to work with
alternative pointing devices for people with mobility problems. Hopefully it
will work and be helpful.

Thanks again Chris!

J

Chris Jensen said:
Hello J,

The easiest way to do all that you list is through a COM add-in. The COM
add-in applies to both Office 2000 and Office 2002 (XP). You can write one
in VB, VB .NET, C#, VC++, VBA and other COM-aware languages. There are
several Microsoft Knowledge Base articles that discuss the subject and give
you sample code. Here is a list of some of them that should help.

238228 HOWTO: Build an Office 2000 COM Add-In in Visual Basic
http://support.microsoft.com/?id=238228
( Look for the section that starts with the line
"Building a COM Add-In Using the VB6 Add-in Designer ")

306130 HOW TO: Create Office COM Add-Ins by Using VBA and Office Developer
http://support.microsoft.com/?id=306130

230689 SAMPLE: Comaddin.exe Office 2000 COM Add-In Written in Visual C++
http://support.microsoft.com/?id=230689

If you are using Excel 2000 this article discusses how to call a method of
a COM add-in from Excel
256624 HOWTO: Use a COM Add-In Function as an Excel Worksheet Function
http://support.microsoft.com/?id=256624

316983 OL: A Sample COM Add-in That Uses the Visual Basic 6.0 Add-in
Template
http://support.microsoft.com/?id=316983
(this is particular to building a COM Add-in for Outlook)

302896 HOW TO: Build an Office COM Add-in by Using Visual Basic .NET
http://support.microsoft.com/?id=302896

302901 HOW TO: Build an Office COM Add-in by Using Visual C# .NET
http://support.microsoft.com/?id=302901

325668 XL2002: Issues Fixed in Excel 2002 by Office XP Service Pack 2
http://support.microsoft.com/?id=325668

322027 OL2002: COM Add-Ins Are Not Trusted If They Are Created with Visual
http://support.microsoft.com/?id=322027

327657 OL2002: How to Create Trusted Outlook COM Add-Ins
http://support.microsoft.com/?id=327657

Other articles that may prove useful to you include:

316723 PRB: Visual Studio .NET Shared Add-in Is Not Displayed in Office COM
http://support.microsoft.com/?id=316723

316724 PRB: Macro Warning Occurs in an Office Application When You Load a
NET
http://support.microsoft.com/?id=316724

253338 INFO: Office Developer Samples and Tools Available for Download
http://support.microsoft.com/?id=253338

The next two articles are about "Automation Add-ins". Those are new with
Excel 2002. With those, Excel can call the functions of the Add-in
directly. However, there are other aspects of an automation add-in that you
may consider impractical when you consider your end-user needs. Please make
your own evaluation.

291392 INFO: Excel COM Add-ins and Automation Add-ins
http://support.microsoft.com/?id=291392

285337 HOWTO: Create a Visual Basic Automation Add-in for Excel 2002
Worksheet
http://support.microsoft.com/?id=285337

More information:

When you say you want to create a separate window you're probably going to
add a Windows form that is created by a menu item. The following
information is deals with a problem using a modeless form, and suggests a
workaround for the problem:

Modeless Windows Form in an Office COM Addin Ignores Keystrokes
-------------------------------------------------------------------------- --
---
This information applies to:

- Microsoft Excel 2002
- Microsoft Word 2002
- Microsoft PowerPoint 2002
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# .NET (2003)

-------------------------------------------------------------------------- --
---

SYMPTOMS
========

You have used Visual Basic .NET or Visual Basic C# to create an Office COM
Addin that displays a modeless Windows Form. When the form has focus,
keystrokes are ignored. This includes the Tab key for cycling between
controls on the form and accelerator keys for controls on the form.

WORKAROUND
==========

To workaround this problem, show the form as a modal dialog using the
ShowDialog method. To achieve functionality similar to a modeless form,
you can show the form modal on a different thread as illustrated below.

1. Follow the steps in the following article to build a basic COM
Addin: KBLink:302896.KB.EN-US: HOW TO: Build an Office COM Add-in by
Using Visual Basic .NET
2. On the Project menu, choose Add Windows Form. Select the Windows
Form template and click Open.
3. Add two Button controls to Form1.
4. In connect.vb, replace the code in MyButton_Click with:

Dim frm As New Form1()
frm.Show()
5. On the Build menu, choose Build Solution.
6. Start Excel and click the custom commandbar button that the COM
Addin creates.
7. When Form1 appears, press Tab to cycle the two buttons. Notice that
the Tab key is not recognized by the form.
8. Close the form and quit Excel.
9. To workaround this problem so the Tab keys (and other keys) are
recognized by the Windows Form:
a. Add a new class to the Form1 class:

Public Class MyThread
Public Sub MyThreadProc()
Dim frm As New Form1()
frm.ShowDialog()
End Sub
End Class
b. Replace the code in MyButton_Click with:

Dim oTHandler As MyThread = New MyThread()
Dim oStart As System.Threading.ThreadStart = New
System.Threading.ThreadStart(AddressOf oTHandler.MyThreadProc)
Dim oT As System.Threading.Thread = New System.Threading.Thread(oStart)
oT.Start()
c. On the Build menu, choose Build Solution.
d. Start Excel and test the Form again. Now, pressing the Tab key will
cycle the controls on the form as expected.

A Modal form won't have a menu, but you can use Command Buttons to provide
the same functionality. Or, you can use VB 6.0 to build the Add-on and in
that use a Modeless form.

Best wishes for the success of your project.


--------------------
From: "j" <[email protected]>
Subject: Need to know how to access Office Events to extend Office apps
Date: Tue, 1 Jul 2003 09:41:07 -0400
Hi, I need a little direction to get me going.

What I'm wanting to do is for any Office application:
1. Capture a Menu click event
2. Capture that Menu's items (submenu)
3. Create a seperate window with those submenu items
4. Capture submenu item click on the new window
5. Send submenu item click event back to Office application's submenu

The target is Office 2000 and Office XP.

Is VBA the way to do this? Or can an app be written in C# or VB and used to
extend Office? If someone could point me in the right dorection. So far, I
cannot find clear instructions on how to extend Office in this way.

Regards,
Chris Jensen[MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
<http://www.microsoft.com/security>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top