PDA

View Full Version : Solved: Underlying Title Case of Word Style



ABrown
06-19-2008, 01:52 AM
I have documents that are imported into our system that we have to "paste special unformatted text" into our template. The problem is that heading level 1 (which is used in the TOC) has underlying upper case text and this needs to be title case text so that when we generate the TOC it in the correct title case format. I have tried a macro to search and replace the heading text, changing the case to title case but it won't work throughout the document. Is there a way I can search on the style, change its underlying case and then format back into the style of Heading 1 so that it appears in the TOC correctly.

I have had several attempts at writing some VBA to do the job, but have hit a wall and everything I have tried fails!! Any help, on even where to start, would be a massive help!! :doh:

fumei
06-19-2008, 09:05 AM
Just a little clarity on TOC and the styles it uses.

Generating a ToC causes Word to look for specific styles to be used for the ToC. The default is Heading 1, Heading 2...etc.

So Word looks for instances of Heading 1, and using found instances for the ToC entries.

However, the actual entry (what shows in the TOC) uses a TOC style. So, no matter how Heading 1 is actually formatted, TOC 1 is the format in the TOC.

So say Heading 1 is formatted as TitleCase, and TOC 1 is formatted as UpperCase. The entry in the TOC uses TOC 1, so it is UpperCase. You could make Heading 1, 7 pt, and LowerCase, but it would still show in the TOC as whatever is the format of TOC 1.

So, you can have a different format for the heading, and the actual entry in the TOC.

Change the format of the TOC 1 style itself. For example, I have my Level 1 TOC bolded.

BTW: as mentioned, a generated TOC uses the default of Heading 1, Heading 2...etc. But it does NOT have to use Heading 1. You can generate a TOC using any style you want.

A generated TOC can be made to use (and this is a real example):

TeachingModule (Level 1)
ModuleLeft1 (Level 2)
Para1Head (Level 3)

ABrown
06-23-2008, 01:53 AM
Thanks Steve, how do I make a style to be title case? When I go to modify the style I don't get any options for the case, only whether to make it caps or small caps. Is there a way I can get the style to force title case?

Thanks for your help.

Annette

fumei
06-23-2008, 08:40 AM
No. I don't know about 2007, but you can not make a Style Title case. Case is a property of a Range, not a Style.

You can however, decide that a specific style will be made Titlecase. Like this:

Sub MakeTitleCase()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If oPara.Style = "MyTitle" Then
oPara.Range.Case = wdTitleWord
End If
Next
End Sub

This goes through and explicitly sets any paragraph with a "MyTitle" style to be Titlecase.

fumei
06-23-2008, 08:45 AM
Sorry, actually, it would be more correct to do:

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
Select Case oPara.Style
Case "TOC 1"
oPara.Range.Case = wdTitleWord
Case "TOC 2"
oPara.Range.Case = wdTitleSentence
End Select
Next

This sets the TOC 1 paragraphs TitleCase. You need to explicitly set TOC 2 to NOT be titlecase, as it picks up the attribute from TOC 1.

ABrown
06-23-2008, 08:51 AM
Steve - you're a genius - that is exactly what I need to do - If TOC1 and TOC2 are set explicitly then it doesn't matter what the underlying style is! Thank you so much for your help (again!).

Regards.

Annette :bow:

fumei
06-23-2008, 09:50 AM
It is Gerry actually. The reference is to something that Steve (handle = lucas) wrote here once.

"If TOC1 and TOC2 are set explicitly then it doesn't matter what the underlying style is!"

Precisely. Although to call it "underlying style" is not technically correct. There is no underlying style.

The ToC is generated by setting explicit styles to use to identify entries - and again, the defaults are Heading 1 etc, but can be ANY styles - and with the generated paragraphs (the line items in the ToC) using a TOC style.

Glad I could help.

ABrown
06-24-2008, 02:18 AM
Sorry Gerry!! Thanks once again. Annette

fumei
06-24-2008, 07:21 PM
Not a problem. It has happened before. Steve, I think, gets a kick out of it. I am happy to amuse him.

LOL