VBA select paragraphs to set style

  • Follow


I'm trying to automate formatting of a Table of Contents document.

How can I use VBA to find all paragraphs that do NOT include a tab followed 
by a number (page number) and change the style setting for those paragraphs? 
(These are the chapters.)  

I know how to change the style, but I'm not sure how to evaluate what the 
paragraph "contains". I'm using Word 2002 SP3.
0
Reply Utf 11/19/2009 6:36:05 PM

Hi,

The following macro applies the Heading 2 style to all paragraphs in a 
document that do not contain a tab followed by a number. 

Sub ApplyStyleSelectively()
    Dim prg As Paragraph

    For Each prg In ActiveDocument.Paragraphs
        If prg.Range.Find.Execute(findText:="^t^#", _
            Wrap:=wdFindStop, Forward:=True) = False Then
            prg.Style = wdStyleHeading2
        End If
    Next
End Sub

-- 
Hope this helps,
Pesach Shelnitz 


"caten" wrote:

> I'm trying to automate formatting of a Table of Contents document.
> 
> How can I use VBA to find all paragraphs that do NOT include a tab followed 
> by a number (page number) and change the style setting for those paragraphs? 
> (These are the chapters.)  
> 
> I know how to change the style, but I'm not sure how to evaluate what the 
> paragraph "contains". I'm using Word 2002 SP3.
1
Reply Utf 11/20/2009 11:03:02 AM

1 Replies
2789 Views

(page loaded in 1.016 seconds)

10/19/2014 6:16:10 PM


Reply: