WordBasic and c#

D

Dominic

Hi,

I'm tring to call the DisableAutoMacros method (well I think it's a
method) of the Word.WordBasic object.

This is returned as a _ComObject so I can not access this method
directly.

I have tried the following:

Word.Application MSWord = new Word.ApplicationClass();
object WordBasic = MSWord.WordBasic;

WordBasic.GetType().InvokeMember("DisableAutoMacros",
BindingFlags.Static | BindingFlags.Public |
BindingFlags.InvokeMethod, null,
WordBasic, new object [] {});

or

object MSWord = Activator.CreateInstance(t);
object WordBasic = MSWord.GetType().InvokeMember("WordBasic",
BindingFlags.Static | BindingFlags.Public |
BindingFlags.InvokeMethod, null, MSWord, new object [] {});

WordBasic.GetType().InvokeMember("DisableAutoMacros",
BindingFlags.Static | BindingFlags.Public |
BindingFlags.InvokeMethod, null,
WordBasic, new object [] {});

This gives a Exception of :
Exception has been thrown by the target of an invocation.
with an inner Exception of :
Member not found.

If I change the call from "DisableAutoMacros" to something else like
"DisableAyutoMacrossss" I get the exception :
Unknown name.

I assume it can find DisableAutoMacros due to the different execption
messages but I still can't find a way of calling it.

Any help would be most apprecated.

Dominic Godin
 
H

Howard Kaikow

It is easier to use VB .NET, instead of C#, with VBA.

In any case, in VB .NET you would use something like

WordBasic.DisableAutoMacros(1)
 
L

Liana

Here is my code to FilePrintSetup method of WordBasic
C#
Word._Application m_oWord=null;
m_oWord = new Word.Application();
m_oWord.Visible=true;

oWordbasic=m_oWord.WordBasic;


object[] argValues = new object[] {"Adobe PDF", 1}; //first arg is a
printer name
String [] argNames = new String [] {"Printer",
"DoNotSetAsSysDefault"};

oWordbasic.GetType().InvokeMember("FilePrintSetup",
BindingFlags.InvokeMethod,null, oWordbasic,
argValues,null,null,argNames);


Since DisableAutoMacros does not have named arguments
The call is
object[] argValues = new object[] {1};

oWordbasic.GetType().InvokeMember("DisableAutoMacros",
BindingFlags.InvokeMethod,null, oWordbasic,
argValues,null,null,null);
 

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