Table of Contents: A Heading style on only part of a line

G

Gary Schankula

In Word 2002, I have a line like:

ABC Co. ^t 905-555-1234

where ^t is a tab character obviously. I would like ABC Co. to be in
the Table of Contents, but not the phone number. I can manually set
ABC Co. to a Heading style, while the rest of the line remains, say,
Normal, and thus create my ToC that way. But the document is too huge
to do anything manually.

So I've tried Using Wildcards in a global Find and Replace, but each
time I've tried assigning one side of the tab or the other side to a
particular style, the entire line takes on that style. I then thought
that I could use the TC Field Code to specify the exact text I want in
the ToC. But again, I can manually do it no problem, but I have no
way to generate the Ctrl-F9 Field braces in the Replace With box in
Find & Replace.

By the way, my whole purpose in all this is to create a PDF document
from this Word document for both printing and use in Adobe Reader,
with Acrobat Bookmarks generated from the Word Heading styles. Any
help with my problem would be greatly appreciated.

Thanks,
Gary

Gary Schankula
Information Niagara
St. Catharines, Ontario, Canada
www.informationniagara.com
 
D

Doug Robbins - Word MVP

Use a macro containing the following code:

Dim myrange As Range
Dim ftext As String

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="^t[0-9]{3}-[0-9]{3}-[0-9]{4}^13",
Forward:=True, MatchWildcards:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
myrange.Collapse wdCollapseStart
myrange.start = myrange.Paragraphs(1).Range.start
ftext = myrange.Text
myrange.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldTOCEntry,
Text:=ftext
myrange.End = myrange.Paragraphs(1).Range.End + 1
myrange.Collapse wdCollapseEnd
Loop
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
 
G

Gary Schankula

Hi Doug!

Thank you for your response and efforts. I was excited for a bit
there because your code did indeed allow me to insert TC fields into
the doc and create the Table of Contents I wanted. Unfortunagely, it
also allowed me to confirm that Acrobat Bookmarks (my ultimate goal)
can only be created using Word Styles (like Heading styles) and not
from the ToC.

So I'm back to my original problem of getting two Word Styles to share
the same line--programmatically.

ABC Co. ^t 905-555-1234

I need to set ABC Co. to style Heading 2 and keep the tab and whatever
comes after it another style, say Phone.

Does anyone have any ideas?

Thanks,
Gary

Gary Schankula
Information Niagara
St. Catharines, Ontario, Canada
www.informationniagara.com

Use a macro containing the following code:

Dim myrange As Range
Dim ftext As String

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="^t[0-9]{3}-[0-9]{3}-[0-9]{4}^13",
Forward:=True, MatchWildcards:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
myrange.Collapse wdCollapseStart
myrange.start = myrange.Paragraphs(1).Range.start
ftext = myrange.Text
myrange.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldTOCEntry,
Text:=ftext
myrange.End = myrange.Paragraphs(1).Range.End + 1
myrange.Collapse wdCollapseEnd
Loop
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


In Word 2002, I have a line like:
ABC Co. ^t 905-555-1234
where ^t is a tab character obviously. I would like ABC Co. to be in
the Table of Contents, but not the phone number. I can manually set
ABC Co. to a Heading style, while the rest of the line remains, say,
Normal, and thus create my ToC that way. But the document is too huge
to do anything manually.
So I've tried Using Wildcards in a global Find and Replace, but each
time I've tried assigning one side of the tab or the other side to a
particular style, the entire line takes on that style. I then thought
that I could use the TC Field Code to specify the exact text I want in
the ToC. But again, I can manually do it no problem, but I have no
way to generate the Ctrl-F9 Field braces in the Replace With box in
Find & Replace.
By the way, my whole purpose in all this is to create a PDF document
from this Word document for both printing and use in Adobe Reader,
with Acrobat Bookmarks generated from the Word Heading styles. Any
help with my problem would be greatly appreciated.

Gary Schankula
Information Niagara
St. Catharines, Ontario, Canada
www.informationniagara.com
 
D

Doug Robbins - Word MVP

You may be able to do it if you replace the tab with a paragraph mark and
format that mark as hidden.

--
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

Gary Schankula said:
Hi Doug!

Thank you for your response and efforts. I was excited for a bit
there because your code did indeed allow me to insert TC fields into
the doc and create the Table of Contents I wanted. Unfortunagely, it
also allowed me to confirm that Acrobat Bookmarks (my ultimate goal)
can only be created using Word Styles (like Heading styles) and not
from the ToC.

So I'm back to my original problem of getting two Word Styles to share
the same line--programmatically.

ABC Co. ^t 905-555-1234

I need to set ABC Co. to style Heading 2 and keep the tab and whatever
comes after it another style, say Phone.

Does anyone have any ideas?

Thanks,
Gary

Gary Schankula
Information Niagara
St. Catharines, Ontario, Canada
www.informationniagara.com

Use a macro containing the following code:

Dim myrange As Range
Dim ftext As String

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="^t[0-9]{3}-[0-9]{3}-[0-9]{4}^13",
Forward:=True, MatchWildcards:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
myrange.Collapse wdCollapseStart
myrange.start = myrange.Paragraphs(1).Range.start
ftext = myrange.Text
myrange.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldTOCEntry,
Text:=ftext
myrange.End = myrange.Paragraphs(1).Range.End + 1
myrange.Collapse wdCollapseEnd
Loop
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


In Word 2002, I have a line like:
ABC Co. ^t 905-555-1234
where ^t is a tab character obviously. I would like ABC Co. to be in
the Table of Contents, but not the phone number. I can manually set
ABC Co. to a Heading style, while the rest of the line remains, say,
Normal, and thus create my ToC that way. But the document is too huge
to do anything manually.
So I've tried Using Wildcards in a global Find and Replace, but each
time I've tried assigning one side of the tab or the other side to a
particular style, the entire line takes on that style. I then thought
that I could use the TC Field Code to specify the exact text I want in
the ToC. But again, I can manually do it no problem, but I have no
way to generate the Ctrl-F9 Field braces in the Replace With box in
Find & Replace.
By the way, my whole purpose in all this is to create a PDF document
from this Word document for both printing and use in Adobe Reader,
with Acrobat Bookmarks generated from the Word Heading styles. Any
help with my problem would be greatly appreciated.

Gary Schankula
Information Niagara
St. Catharines, Ontario, Canada
www.informationniagara.com
 
R

Russ

Gary,
This goes along with what Doug said:
<http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=177>
You may be able to do it if you replace the tab with a paragraph mark and
format that mark as hidden.

--
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

Gary Schankula said:
Hi Doug!

Thank you for your response and efforts. I was excited for a bit
there because your code did indeed allow me to insert TC fields into
the doc and create the Table of Contents I wanted. Unfortunagely, it
also allowed me to confirm that Acrobat Bookmarks (my ultimate goal)
can only be created using Word Styles (like Heading styles) and not
from the ToC.

So I'm back to my original problem of getting two Word Styles to share
the same line--programmatically.

ABC Co. ^t 905-555-1234

I need to set ABC Co. to style Heading 2 and keep the tab and whatever
comes after it another style, say Phone.

Does anyone have any ideas?

Thanks,
Gary

Gary Schankula
Information Niagara
St. Catharines, Ontario, Canada
www.informationniagara.com

Use a macro containing the following code:

Dim myrange As Range
Dim ftext As String

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="^t[0-9]{3}-[0-9]{3}-[0-9]{4}^13",
Forward:=True, MatchWildcards:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
myrange.Collapse wdCollapseStart
myrange.start = myrange.Paragraphs(1).Range.start
ftext = myrange.Text
myrange.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldTOCEntry,
Text:=ftext
myrange.End = myrange.Paragraphs(1).Range.End + 1
myrange.Collapse wdCollapseEnd
Loop
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



In Word 2002, I have a line like:

ABC Co. ^t 905-555-1234

where ^t is a tab character obviously. I would like ABC Co. to be in
the Table of Contents, but not the phone number. I can manually set
ABC Co. to a Heading style, while the rest of the line remains, say,
Normal, and thus create my ToC that way. But the document is too huge
to do anything manually.

So I've tried Using Wildcards in a global Find and Replace, but each
time I've tried assigning one side of the tab or the other side to a
particular style, the entire line takes on that style. I then thought
that I could use the TC Field Code to specify the exact text I want in
the ToC. But again, I can manually do it no problem, but I have no
way to generate the Ctrl-F9 Field braces in the Replace With box in
Find & Replace.

By the way, my whole purpose in all this is to create a PDF document
from this Word document for both printing and use in Adobe Reader,
with Acrobat Bookmarks generated from the Word Heading styles. Any
help with my problem would be greatly appreciated.

Thanks,
Gary

Gary Schankula
Information Niagara
St. Catharines, Ontario, Canada
www.informationniagara.com
 

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