Accessing WordBasic through C sharp

C

Cindy Meister

Hi all

VS 2003, Office 2003

I'm looking for a way to use WordBasic commands via C#. I found the
following discussion (May 2004) using Google
http://groups.google.ch/group/micro...=WordBasic+NET&rnum=32&hl=de#300613d42debd272

and tried Liana's suggestion in my code, as below. It compiles (which is
definitely an improvement!), but when I run this procedure
- The first message box works fine, and the file path is correct.
- I get an error in mscorlib on the second MessageBox with the text
'Unknown Name.'

Does anyone have any ideas that might help?

private void Pfadangaben(string pfadangabe)
{
MessageBox.Show(pfadangabe);
object wb = wdApp.WordBasic;
object [] argValues = new object[] {2000, 5, 5};
string [] argNames = new string[] {"Year", "Month", "Day"};
MessageBox.Show( (string) wb.GetType().InvokeMember("DateSerial()",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, null, argNames));
//object[] argValues = new object[] {pfadangabe, 1};
//String [] argNames = new String [] {"Filename$", "InfoType"};
//MessageBox.Show((string) wb.GetType().InvokeMember("FileNameInfo$",
//System.Reflection.BindingFlags.InvokeMethod,null, wb, argValues, null,
null, argNames));
}

-- Cindy
 
P

Perry

Hi Cindy,

Have you tried to change the name of DateSerial() in the InvokeMember in the
GetType function ?
It expects the name of a member (string) , so: "DateSerial" should work
(note: without parenthesis)
The parameters of the function DateSerial() function are passed correctly in
the argNames/argValues variables.

-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
 
C

Cindy Meister

Hi Perry
Have you tried to change the name of DateSerial() in the InvokeMember in the
GetType function ?
It expects the name of a member (string) , so: "DateSerial" should work
(note: without parenthesis)
The parameters of the function DateSerial() function are passed correctly in
the argNames/argValues variables.
You mean like this:

MessageBox.Show( (string) wb.GetType().InvokeMember("'DateSerial'",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, ci, argNames));

Same result (Unkown name in mscorlib). Note: I had tried it without
parentheses as well (actually, that's how I had it, first). Same thing...

On the off chance it might be a CulturalInfo issue, I also tried it on a
pure en-US system. Same problem, there...

-- Cindy
-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Cindy Meister said:
Hi all

VS 2003, Office 2003

I'm looking for a way to use WordBasic commands via C#. I found the
following discussion (May 2004) using Google
http://groups.google.ch/group/micro...=WordBasic+NET&rnum=32&hl=de#300613d42debd272

and tried Liana's suggestion in my code, as below. It compiles (which is
definitely an improvement!), but when I run this procedure
- The first message box works fine, and the file path is correct.
- I get an error in mscorlib on the second MessageBox with the text
'Unknown Name.'

Does anyone have any ideas that might help?

private void Pfadangaben(string pfadangabe)
{
MessageBox.Show(pfadangabe);
object wb = wdApp.WordBasic;
object [] argValues = new object[] {2000, 5, 5};
string [] argNames = new string[] {"Year", "Month", "Day"};
MessageBox.Show( (string) wb.GetType().InvokeMember("DateSerial()",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, null, argNames));
//object[] argValues = new object[] {pfadangabe, 1};
//String [] argNames = new String [] {"Filename$", "InfoType"};
//MessageBox.Show((string) wb.GetType().InvokeMember("FileNameInfo$",
//System.Reflection.BindingFlags.InvokeMethod,null, wb, argValues, null,
null, argNames));
}

-- Cindy
 
P

Perry

Hi Cindy,

Try to invoke the DateSerial() function under the wdApp namespace and not
under your WordBasic object, like in

MessageBox.Show( (string) wdApp.GetType().InvokeMember("'DateSerial'",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, ci, argNames));

-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Cindy Meister said:
Hi Perry
Have you tried to change the name of DateSerial() in the InvokeMember in
the
GetType function ?
It expects the name of a member (string) , so: "DateSerial" should work
(note: without parenthesis)
The parameters of the function DateSerial() function are passed correctly
in
the argNames/argValues variables.
You mean like this:

MessageBox.Show( (string) wb.GetType().InvokeMember("'DateSerial'",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, ci, argNames));

Same result (Unkown name in mscorlib). Note: I had tried it without
parentheses as well (actually, that's how I had it, first). Same thing...

On the off chance it might be a CulturalInfo issue, I also tried it on a
pure en-US system. Same problem, there...

-- Cindy
-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Cindy Meister said:
Hi all

VS 2003, Office 2003

I'm looking for a way to use WordBasic commands via C#. I found the
following discussion (May 2004) using Google
http://groups.google.ch/group/micro...=WordBasic+NET&rnum=32&hl=de#300613d42debd272

and tried Liana's suggestion in my code, as below. It compiles (which
is
definitely an improvement!), but when I run this procedure
- The first message box works fine, and the file path is correct.
- I get an error in mscorlib on the second MessageBox with the text
'Unknown Name.'

Does anyone have any ideas that might help?

private void Pfadangaben(string pfadangabe)
{
MessageBox.Show(pfadangabe);
object wb = wdApp.WordBasic;
object [] argValues = new object[] {2000, 5, 5};
string [] argNames = new string[] {"Year", "Month", "Day"};
MessageBox.Show( (string) wb.GetType().InvokeMember("DateSerial()",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, null, argNames));
//object[] argValues = new object[] {pfadangabe, 1};
//String [] argNames = new String [] {"Filename$", "InfoType"};
//MessageBox.Show((string) wb.GetType().InvokeMember("FileNameInfo$",
//System.Reflection.BindingFlags.InvokeMethod,null, wb, argValues,
null,
null, argNames));
}

-- Cindy
 
P

Perry

Cindy, actually DateSerial() is part of the VBA interface.
It isn't a member of the Word application object, so my last suggestion
won't work either.
If you can hook up to the VBA interface, you should be able to invoke the
DateSerial() function ...
-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Perry said:
Hi Cindy,

Try to invoke the DateSerial() function under the wdApp namespace and not
under your WordBasic object, like in

MessageBox.Show( (string) wdApp.GetType().InvokeMember("'DateSerial'",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, ci, argNames));

-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Cindy Meister said:
Hi Perry
Have you tried to change the name of DateSerial() in the InvokeMember in
the
GetType function ?
It expects the name of a member (string) , so: "DateSerial" should work
(note: without parenthesis)
The parameters of the function DateSerial() function are passed
correctly in
the argNames/argValues variables.
You mean like this:

MessageBox.Show( (string) wb.GetType().InvokeMember("'DateSerial'",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, ci, argNames));

Same result (Unkown name in mscorlib). Note: I had tried it without
parentheses as well (actually, that's how I had it, first). Same thing...

On the off chance it might be a CulturalInfo issue, I also tried it on a
pure en-US system. Same problem, there...

-- Cindy
-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Hi all

VS 2003, Office 2003

I'm looking for a way to use WordBasic commands via C#. I found the
following discussion (May 2004) using Google
http://groups.google.ch/group/micro...=WordBasic+NET&rnum=32&hl=de#300613d42debd272

and tried Liana's suggestion in my code, as below. It compiles (which
is
definitely an improvement!), but when I run this procedure
- The first message box works fine, and the file path is correct.
- I get an error in mscorlib on the second MessageBox with the text
'Unknown Name.'

Does anyone have any ideas that might help?

private void Pfadangaben(string pfadangabe)
{
MessageBox.Show(pfadangabe);
object wb = wdApp.WordBasic;
object [] argValues = new object[] {2000, 5, 5};
string [] argNames = new string[] {"Year", "Month", "Day"};
MessageBox.Show( (string) wb.GetType().InvokeMember("DateSerial()",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, null, argNames));
//object[] argValues = new object[] {pfadangabe, 1};
//String [] argNames = new String [] {"Filename$", "InfoType"};
//MessageBox.Show((string) wb.GetType().InvokeMember("FileNameInfo$",
//System.Reflection.BindingFlags.InvokeMethod,null, wb, argValues,
null,
null, argNames));
}

-- Cindy
 
C

Cindy Meister

Hi Perry

There may well be a DateSerial function as part of the VBA object model. But
that's not what I'm after.

DateSerial just seemed to be a WordBasic function that would be fairly
simple to test. If you looked at the code example I posted, I also had
FileNameInfo$ in there (commented out). And I mentioned the command the
posting I quoted, as well. I can't get any of it to work using any interface
in C# (late binding). What I can do is create a wrapper class in VB.NET, then
call that.

But what I really WANT is to do this (be able to access the WordBasic
functionality) in a C# class...

-- Cindy

Perry said:
Cindy, actually DateSerial() is part of the VBA interface.
It isn't a member of the Word application object, so my last suggestion
won't work either.
If you can hook up to the VBA interface, you should be able to invoke the
DateSerial() function ...
-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Perry said:
Hi Cindy,

Try to invoke the DateSerial() function under the wdApp namespace and not
under your WordBasic object, like in

MessageBox.Show( (string) wdApp.GetType().InvokeMember("'DateSerial'",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, ci, argNames));

-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Cindy Meister said:
Hi Perry

Have you tried to change the name of DateSerial() in the InvokeMember in
the
GetType function ?
It expects the name of a member (string) , so: "DateSerial" should work
(note: without parenthesis)
The parameters of the function DateSerial() function are passed
correctly in
the argNames/argValues variables.

You mean like this:

MessageBox.Show( (string) wb.GetType().InvokeMember("'DateSerial'",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, ci, argNames));

Same result (Unkown name in mscorlib). Note: I had tried it without
parentheses as well (actually, that's how I had it, first). Same thing...

On the off chance it might be a CulturalInfo issue, I also tried it on a
pure en-US system. Same problem, there...

-- Cindy

-------------------------------------
Krgrds,
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
Hi all

VS 2003, Office 2003

I'm looking for a way to use WordBasic commands via C#. I found the
following discussion (May 2004) using Google
http://groups.google.ch/group/micro...=WordBasic+NET&rnum=32&hl=de#300613d42debd272

and tried Liana's suggestion in my code, as below. It compiles (which
is
definitely an improvement!), but when I run this procedure
- The first message box works fine, and the file path is correct.
- I get an error in mscorlib on the second MessageBox with the text
'Unknown Name.'

Does anyone have any ideas that might help?

private void Pfadangaben(string pfadangabe)
{
MessageBox.Show(pfadangabe);
object wb = wdApp.WordBasic;
object [] argValues = new object[] {2000, 5, 5};
string [] argNames = new string[] {"Year", "Month", "Day"};
MessageBox.Show( (string) wb.GetType().InvokeMember("DateSerial()",
System.Reflection.BindingFlags.InvokeMethod,
null, wb, argValues, null, null, argNames));
//object[] argValues = new object[] {pfadangabe, 1};
//String [] argNames = new String [] {"Filename$", "InfoType"};
//MessageBox.Show((string) wb.GetType().InvokeMember("FileNameInfo$",
//System.Reflection.BindingFlags.InvokeMethod,null, wb, argValues,
null,
null, argNames));
}

-- Cindy
 
Top