Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

In VSTO C# for Powerpoint, how to check if a VBA macro exists ?

46 views
Skip to first unread message

Geossl

unread,
Jul 6, 2009, 3:32:01 AM7/6/09
to
Dear All,

In VSTO of C# for PowerPoint, is there any way to check if a VBA macro
exists? before calling the VBA?

Or just call and see if there is exception?


Cindy M.

unread,
Jul 10, 2009, 3:14:36 AM7/10/09
to

Hi Geossl,

> In VSTO of C# for PowerPoint, is there any way to check if a VBA macro
> exists? before calling the VBA?

This isn't VSTO specific, but it can be done. What you need is the VBE
(Visual Basic for Application Extensibility) type library. You need to
set a reference to this in your project, then you need to learn how to
use it.

The VBE is unfortunately not well-documented. The best "playground" is to
work in the native VBA IDE until you're familiar with the basic syntax.
This will give you direct access to what little Help documentation there
is.

In the Word application, press Alt+F11 to open the IDE. Press Ctrl+G to
open the "Immediate" window. In Tool/References, activate the checkbox
next to the entry "Microsoft Visual Basic for Application Extensibility
5.3". To get started on investigating the OM, in that window, type:

?ActiveDocument.VBProject.VBComponents.Count

Then press Enter. You'll probably get back the value: 1 (one)

Then try:

?ActiveDocument.VBProject.VBComponents(1).Name

And press Enter. The result will likely be: ThisDocument (the class
module associated with every Word document)

In this way, using Intellisense, you can explore the object model. Click
in any term, then press F1 to bring up the context-sensitive Help.

FWIW, what I think you need is the following. If the procedure name does
not exist, run-time error 35 is returned, which you should be able to
trap. For VBA this is not problem. For .NET and structured error handling
this would mean a preformance hit. So you could, perhaps, use the Find
method, instead.

docobject.VBProject.VBComponents(1).CodeModule.ProcStartLine("Test1",
vbext_pk_Proc)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :-)

0 new messages