views:

49

answers:

2

Hi to everyone.

I've got a tiny (I hope) problem again, and I don't know how to obtain access to some presentation properties provided by PowerPoint (however I don't even know how to google it or search it at the site :( ) from C#. Let me explain. We can access a TextRange property both in C# and VBA, via an interop assembly and ms-office-built-in VBA editor respectively. It's ok, but this property contains two same-named entities - Runs. VBA allows to access it as a method and as a property (moreover, Runs property object insides are useful), but the property Runs in not accessible via the interop assembly, Runs() method can be accessed only (and it returns text run objects). I've digged in the interop assembly using .NET Reflector but I have not found anything related to the Runs property (though properties with different unique rather than methods names have own get_Property() and set_Property() methods). It seems that the interop assembly is missing the Runs property for TextRange interface. Frankly, I'm not sure. :(

Can I somehow obtain the access Runs property from C#? I'm not familiar with COM, etc, and I hope for your help. Thanks.

+1  A: 

I think you are talking about the Microsoft.Office.Core.TextRange2.Runs() property. It is a property that takes two arguments, start and length. Such a property is not directly accessible in the C# language, at least not until C# 4.0. Only Visual Basic supports indexed properties right now.

The workaround is to use get_Runs() instead.

Hans Passant
Thank you for reply. No, I use Microsoft.Office.Interop.PowerPoint.TextRange, and it does not contain a definition for get_Runs(). :( Also, unfortunately I must note I use C# 2.0 and PowerPoint 2003.
Lyubomyr Shaydariv
Microsoft.Office.Interop.PowerPoint.TextRange has a Runs() method, it is not a property. Beware that these TextRange classes are not identical, you can't mix a Word TextRange with a PowerPoint TextRange.
Hans Passant
However Microsoft.Office.Interop.PowerPoint.TextRange.Runs is also a property, and it's pretty seen from VBA. You have noticed it above in the answer. As far as I can see, I point the same entity both from C# and VBA. Sure, I cannot mix TextRange-s from Office and PowerPoint namespaces, but it is not necessary. I just want to get .TextRange.Runs.Count property. It is the only reason of the question. :) But... Probably can I somehow update the generated interop library when there's no source code? I would like to enhance it with something like get_RunsData(). Something like this I guess.
Lyubomyr Shaydariv
You know... Emmm... Nevermind, nobugz. I'll try somewhat another way, though I'm still confused. Maybe I'm wrong. Thank you. :)
Lyubomyr Shaydariv
VBA allows omitting the (). Not C#, .TextRange.Runs().Count
Hans Passant
I was wrong, and you were right saying "it is not a property", nobugz. :D It's my lack of knowing the VB syntax: I didn't know that a method that can be invoked with no parameters visually looks like a property! Wow... This made me confused! :D Thanks again! :D
Lyubomyr Shaydariv
A: 

In C# you have to specify where to start and where to end:

...

foreach (TextRange txtrn in txtrng.Runs(0, txtrng.Length)) {

if(txtrn.Font.Name =="Arial") MessageBox.Show(txtrn.Text);

}

.....

jehell
Thanks, but the issue was incomplete misunderstanding of VB(A) syntax where methods with all omitted parameters look like properties.
Lyubomyr Shaydariv