Varun Walia
asked on
How to check "para" & "character" style, in same paragraph?
How to check a paragraph that it contain both paragraph style and character style in it.
Sample document is attached herewith.
We have to check that paragraph style "ref" and character style is "Volume" exist in the document using VBA macro.
Thanks
CH05_CE.doc
Sample document is attached herewith.
We have to check that paragraph style "ref" and character style is "Volume" exist in the document using VBA macro.
Thanks
CH05_CE.doc
ASKER
I try something like this to check character style in ref paragraph styles. Please suggest!!
Sub FindNewCharStyles()
Dim docActive As Document
Dim docNew As Document
Dim styleLoop As Style
Dim StyleArr() As String
refCharArr(1) = "First page"
refCharArr(2) = "Last page"
refCharArr(3) = "Default Paragraph Font"
i = 1
Set docActive = ActiveDocument
For Each styleLoop In docActive.Styles
If (styleLoop.InUse = True And styleLoop.Type = wdStyleTypeCharacter) Then
If (Not inRef(styleLoop.NameLocal)) Then
ReDim Preserve StyleArr(i)
StyleArr(i) = styleLoop.NameLocal
i = i + 1
End If
End If
Next styleLoop
For J = 1 To UBound(StyleArr)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = ""
.Style = StyleArr(J)
While .Execute()
pStyle = Selection.Range.Paragraphs(1).Style
flag = False
If pStyle = "ref" Then
Fileout.Writeline StyleArr(J) & " is a wrong style!"
End If
Wend
End With
Next J
End Sub
Function inRef(rStyle As String)
Dim flag As Boolean
flag = False
For i = 1 To UBound(refCharArr)
If (refCharArr(i) = rStyle) Then flag = True
Next i
inRef = flag
End Function
As in your other question, does my macro not work?
I repeat the comment about Selection vs Range objects and repost the link to my article (it is still in my Windows clipboard)
https://www.experts-exchange.com/articles/9909/Using-the-Word-Range-object-in-code.html
I repeat the comment about Selection vs Range objects and repost the link to my article (it is still in my Windows clipboard)
https://www.experts-exchange.com/articles/9909/Using-the-Word-Range-object-in-code.html
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window