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
Doug Robbins - Word MVP - 23 Aug 2007 20:55 GMT
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

Signature
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:
>
[quoted text clipped - 26 lines]
> St. Catharines, Ontario, Canada
> www.informationniagara.com
Gary Schankula - 23 Aug 2007 22:57 GMT
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
On Aug 23, 3:55 pm, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> Use a macro containing the following code:
>
[quoted text clipped - 56 lines]
> > St. Catharines, Ontario, Canada
> >www.informationniagara.com
Doug Robbins - Word MVP - 24 Aug 2007 10:57 GMT
You may be able to do it if you replace the tab with a paragraph mark and
format that mark as hidden.

Signature
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
> Hi Doug!
>
[quoted text clipped - 85 lines]
>> > St. Catharines, Ontario, Canada
>> >www.informationniagara.com
Russ - 25 Aug 2007 09:00 GMT
Gary,
This goes along with what Doug said:
<http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=177>
<http://msdn2.microsoft.com/en-us/library/aa160667(office.10).aspx>
> You may be able to do it if you replace the tab with a paragraph mark and
> format that mark as hidden.
[quoted text clipped - 88 lines]
>>>> St. Catharines, Ontario, Canada
>>>> www.informationniagara.com

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID