Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2015, 05:24 PM
gn4619 gn4619 is offline How to create a special TOC in word document? Windows 7 64bit How to create a special TOC in word document? Office 2010 32bit
Novice
How to create a special TOC in word document?
 
Join Date: Apr 2015
Posts: 25
gn4619 is on a distinguished road
Default How to create a special TOC in word document?

have a large number of Word documents, and need to divide each document into parts. What I am doing is to manually insert into the text the part splitting phrases, such as:


Part_1

Text goes here...
Part_2
Text goes here...
Part_3
Text goes here...
I want to automate with VBA the task to create a TOC of all these splitting phrases at the beginning of the Word document. Perhaps applying a unique style to these splitters, and then create a TOC for this special style only? I appreciate it very much if anyone can help.
Reply With Quote
  #2  
Old 04-27-2015, 06:22 AM
gmaxey gmaxey is offline How to create a special TOC in word document? Windows 7 32bit How to create a special TOC in word document? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You could create a style say called "SpecTOC" and apply it to you separator phrases. Then run:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
  Set oRng = ActiveDocument.Range
  oRng.Collapse
  
  With ActiveDocument
    .TablesOfContents.Add Range:=oRng, RightAlignPageNumbers:= _
      True, UseHeadingStyles:=False, IncludePageNumbers:=True, AddedStyles _
      :="SpecTOC,1", UseHyperlinks:=True, HidePageNumbersInWeb:=True, _
      UseOutlineLevels:=False
    .TablesOfContents(1).TabLeader = wdTabLeaderDots
    .TablesOfContents.Format = wdIndexIndent
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 04-27-2015, 12:07 PM
gn4619 gn4619 is offline How to create a special TOC in word document? Windows 7 64bit How to create a special TOC in word document? Office 2010 32bit
Novice
How to create a special TOC in word document?
 
Join Date: Apr 2015
Posts: 25
gn4619 is on a distinguished road
Default Thanks!

The only issue with this method is that if you have a lot styles, some other styles may also be included in the TOC in addition to your style. The headings are excluded (as False), but there seems no way to exclude other styles.
Reply With Quote
  #4  
Old 04-27-2015, 06:17 PM
Guessed's Avatar
Guessed Guessed is offline How to create a special TOC in word document? Windows 7 32bit How to create a special TOC in word document? Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Perhaps you should try the code Greg supplied before inventing new issues. Other styles will need to be explicitly put into the TOC if you want them there so if those other styles don't get a mention in the AddedStyles attribute then you shouldn't start worrying about them.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 04-28-2015, 06:40 AM
gn4619 gn4619 is offline How to create a special TOC in word document? Windows 7 64bit How to create a special TOC in word document? Office 2010 32bit
Novice
How to create a special TOC in word document?
 
Join Date: Apr 2015
Posts: 25
gn4619 is on a distinguished road
Default Thanks.

Thanks. I wouldn't say there is an issue if it is not actually what happens. I already used the same method as Greg Maxey's, and for some documents, ended up with a TOC of various styles (except for headings).
Reply With Quote
  #6  
Old 04-29-2015, 04:25 PM
gn4619 gn4619 is offline How to create a special TOC in word document? Windows 7 64bit How to create a special TOC in word document? Office 2010 32bit
Novice
How to create a special TOC in word document?
 
Join Date: Apr 2015
Posts: 25
gn4619 is on a distinguished road
Default I figured out a way

I used TC entries instead, and it works very well.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a special TOC in word document? How do I create an index of every word in a document? jbengal Word 5 11-23-2022 02:17 PM
How to create a special TOC in word document? How to Create Dynamic Paragraphs in Word Document gt7586d Word 3 02-19-2015 01:02 PM
How to create a special TOC in word document? Create a word document by answering questions? mattfrack Word 1 01-09-2015 02:25 PM
How to identify whether Word 2007 was used to create a document saved as Word 2003 noviceatwork Word 0 03-08-2012 06:40 AM
Creating a special Document darka5sa5sin Word 0 02-06-2009 11:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft