Substituting ExitMacro

N

Nemesist

We´ve developed an add-in for Office 2003 in C# for Word and PowerPoint. Our goal was not to use any macros of a previous (Office 2000) version of the application. Except some ExitMacros attached to Word form fields we were succesfull in this.

Could anyone help me to explain how i can substitute ExitMacro-s of a form field in C#? How can I catch the event of leaving a form field?

Any help would be greatly appreciated!

Thanks in advance,
Istvan
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TmVtZXNpc3Q=?=,
We´ve developed an add-in for Office 2003 in C# for Word and PowerPoint. Our goal was
not to use any macros of a previous (Office 2000) version of the application. Except some
ExitMacros attached to Word form fields we were succesfull in this.
Could anyone help me to explain how i can substitute ExitMacro-s of a form field in C#?
How can I catch the event of leaving a form field?Seems to me I answered this the other day... Fields don't trigger any events you can trap
in an automation interface. That means you can't assign a macro button or form field
Enter/Exit directly to managed code.

Closest you could get would be to use the WindowSelectionChange event. Otherwise, you'd
need a "callback".

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the
newsgroup and not by e-mail :)
 
N

Nemesist

Hi Cindy,

thank you very much for the answer. I was about to consider WindowSelectionChange, but I don´t see what do you mean hier by "callback".
Could you give me some more hints about this?

--Istvan
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TmVtZXNpc3Q=?=,
I don´t see what do you mean hier by "callback".
Could you give me some more hints about this?
This is not something I've tried, personally, but here's an
example I picked up a while back. The principle would work
the same in Word.

----
Here's an example for you that illustrates with the
OnKey...

1. Create a new workbook and put the following code in a
module:

Dim managedObject As Object

Public Sub RegisterCallback(callback As Object)
Set managedObject = callback
Application.OnKey "^m", "DoManagedCallBack"
End Sub

Public Sub DoManagedCallBack()
managedObject.HandleCtrlM
End Sub

2. Then, create a new Excel project based on the existing
workbook you
created.

3. Add the following code to the project:

Private Sub ThisWorkbook_Open() Handles
ThisWorkbook.Open
ThisApplication.Run("RegisterCallback", Me)
End Sub

Public Sub HandleCtrlM()
MsgBox("HandleCtrlM")
End Sub

4. Press F5 to run; when you press Ctrl+m in Excel, the
DoManagedCallBack
routine in the assembly is run.

So, what's happening here is that a) you call a macro in
the workbook to
pass it a reference to the assembly's class, b) the macro
stores the
reference to the object, c) you set up OnKey to call a
macro in the
workbook, and d) when the "OnKey" routine fires, it will
use the stored
reference to the object to call a public method
(HandleCtrlM in this
example) in the assembly code. Of course, for this to work,
the VBA
security settings must allow the VBA code in the workbook
to run.
----

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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