Get style name in word from a .Net application

  • Thread starter Allan Schuster Bach
  • Start date
A

Allan Schuster Bach

I want to get the name form a style in a .Net application

VBA code in word (working)

debug .print selection.style


..Net code in application

with worddocument.selection
.style = "Normal" (Working)
msgbox (.style) (Not working
end with


What is wrong?


Bach
 
T

Tom Winter

This is probably a .NET thing. In VB/VBA you can do msgbox(.style). To
understand what is happening here, you need to realize how the Style
property of the Range object works. It is a variant. This means you can set
tht style property to a sring, as in your example, or to another Style
object. But the Style property always RETURNS a Style object, not a string.
The reason that msgbox(.Style) works in VB/VBA is that the default property
of the Style object is NameLocal, which a string. I think I've heard that
..NET doesn't support default properties or something like that, you so you
can't do msgbox(.style) in .NET. But msgbox (.style.NameLocal) should work.
 
P

Peter Hewett

Hi Alan

The problems with the use of Words object model. There is no Selection object
for Documents, it's an Application object vis:

With wdApp.Selection
.Style = "Normal"
MsgBox .Style
End With

HTH + Cheers - Peter
 

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