Skipping table formatting

L

LEU

Graham Mayor was helping me with paragraph formatting and gave me the
following macro to try. How do I get it to skip the paragraph formatting
inside tables?



Dim sStyle As Integer
sStyle = 0
With ActiveDocument
For i = 1 To .Paragraphs.Count
With .Paragraphs(i)
If Left(.Style, 7) = "Heading" Then
sStyle = Right(.Style, 1)
End If
If .Style = "Normal" And sStyle <> 0 Then
.Style = "HD" & sStyle
End If
End With
Next i
End With
 
D

Doug Robbins - Word MVP

Use:

Dim sStyle As Integer
sStyle = 0
With ActiveDocument
For i = 1 To .Paragraphs.Count
With .Paragraphs(i)
If .Range.Information(wdWithInTable) = False Then
If Left(.Style, 7) = "Heading" Then
sStyle = Right(.Style, 1)
End If
If .Style = "Normal" And sStyle <> 0 Then
.Style = "HD" & sStyle
End If
End If
End With
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LEU

Doug,

Your macro worked great. It takes some time to run through a document and
that makes it look like nothing is happening when it runs. Some endusers may
think Word has lockup and will try to cancel or close the document. Is there
a way to show that the macro is working on the document while it runs?
 
D

David Turner

Your macro worked great. It takes some time to run through a document and
that makes it look like nothing is happening when it runs. Some endusers may
think Word has lockup and will try to cancel or close the document. Is there
a way to show that the macro is working on the document while it runs?

One easy way is to insert a StatusBar line displaying a suitable message
indicating that the macro is running.

Dim sStyle As Integer
sStyle = 0
With ActiveDocument
For i = 1 To .Paragraphs.Count
With .Paragraphs(i)
If .Range.Information(wdWithInTable) = False Then
If Left(.Style, 7) = "Heading" Then
sStyle = Right(.Style, 1)
End If
If .Style = "Normal" And sStyle <> 0 Then
..Style = "HD" & sStyle
End If
End If
End With
StatusBar = "Macro running, please wait..."
Next i
End With

David Turner
 

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