Heading 1 carries over into table

K

Krakmup

G'Day

I have encountered a unique heading problem. I generate a table from a
database, move off the table and create a "Heading 1" for my table of
contents, then move back into the table, and format the first line, and
desire to make the first row carry over into new pages.

CODE:
Selection.SelectRow
Selection.ClearFormatting
Selection.Font.Bold = wdToggle
Selection.Font.SmallCaps = wdToggle
Selection.Font.Color = wdColorBlue
Selection.Rows.HeadingFormat = True

The problem, is in Office 2000, and Windows 2000, 98, etc, the second line
is not recognized. If I delete the second line, then the "Heading 1" carries
over into the table.

Any ideas?
Krakmup
 
J

Jean-Guy Marcil

Krakmup was telling us:
Krakmup nous racontait que :
G'Day

I have encountered a unique heading problem. I generate a table from
a database, move off the table and create a "Heading 1" for my table
of contents, then move back into the table, and format the first
line, and desire to make the first row carry over into new pages.

CODE:
Selection.SelectRow
Selection.ClearFormatting
Selection.Font.Bold = wdToggle
Selection.Font.SmallCaps = wdToggle
Selection.Font.Color = wdColorBlue
Selection.Rows.HeadingFormat = True

The problem, is in Office 2000, and Windows 2000, 98, etc, the second
line is not recognized. If I delete the second line, then the
"Heading 1" carries over into the table.

Any ideas?
Krakmup

Try not using the selection object... it leads to more complicated and
unstable code.
Without seeing the code you use to create the table, move out of the table,
create the heading and then move back in the table, it is difficult to help.

But, why do you create an object, move out, do something unrelated to the
object, then move back in the object to do something? Why didn't you do
everything before moving out of the object?

Try this code which does not use the Selection object:

Dim MyTable As Table
Dim StartRge As Range
Dim myRow As Row

Set StartRge = Selection.Range
StartRge.Collapse wdCollapseStart

With StartRge
.InsertAfter "Table Title"
.Style = wdStyleHeading1
.InsertParagraphAfter
.Collapse wdCollapseEnd
.Style = wdStyleNormal
.Tables.Add StartRge, 8, 5
Set myRow = .Tables(1).Rows(1)
With myRow
With .Range.Font
.Bold = True
.SmallCaps = True
.Color = wdColorBlue
End With
.HeadingFormat = True
End With
End With


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Klaus Linke

Hi Krakmup,

ClearFormatting seems to do much the same as applying "Normal" style:
Selection.Range.Style = ActiveDocument.Styles(wdStyleNormal)

The only difference I see is that applying "Normal" (built-in command
DemoteToBodyText, with either whole paragraphs or nothing selected) doesn't
remove character styles, "Clear Formatting" does.

So you might apply wdStyleDefaultParagraphFont, too:
Selection.Font.Reset

OTOH, ClearFormatting even removes manual font formatting from the paragraph
if you haven't anything selected (if the paragraph style isn't "Normal", and
more than 50% of the text has manual formatting).

So if you want to mimic "ClearFormatting" 100%, you might have to write more
code. Most of those built-in commands to remove formatting are inordinately
complicated, trying to guess the user's desire.

Regards,
Klaus
 

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