Style Problem

V

vbaNOOB

Hi all,

I have a problem on Style
In MS word, there are two types of style: Paragraph style and character style

I have a paragraph which is in style A (Para style) originally.
Then I try to create a character style called style B (char style).
And I style the paragraph with style B which origianlly styled as Style A.

Now, I have a para with both style A and style B
The style box will only display 1 type of style for that particular paragraph
However, when u use the 'styles and formatting' box which u can select all
paragraphs with a particular style. U will notice that for both style A and
style B
The paragraph is selected!!!

Also, In vba when I use activedocument.parargraph(1).style, It sometimes
show style A, sometimes show style B. Is that I always I can show all styles
of a paragraph

Many Thanks
 
S

Stefan Blom

In VBA, you will always see the paragraph style if you investigate the Style
property for a Paragraph object. And you will get the character style, if
there is one, if you look at the Style property for a Range object. If no
character style has been applied, the current paragraph style will be
returned instead.

For example, the following simple code returns the paragraph style of the
first paragraph and the character style of the first character of the
current selection (technically, what I get in this example is the *names* of
the applied styles):

Sub Testing()

Dim ParaStyleName As String
Dim CharStyleName As String

ParaStyleName = Selection.Paragraphs(1).Style.NameLocal

CharStyleName = Selection.Characters(1).Style.NameLocal

'Print results to the Immediate window of the VBA Editor:

Debug.Print "Para style: " & ParaStyleName
Debug.Print "Char style: " & CharStyleName

End Sub

If you are using Word 2007, you can directly return the character and
paragraph style names, respectively (again, the examples actually return the
style names):

Debug.Print Selection.Characters(1).CharacterStyle.NameLocal
Debug.Print Selection.Paragraphs(1).Range.ParagraphStyle.NameLocal

If there is no character style applied, the built-in "Default Paragraph
Font" character style will be returned instead.

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 

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