Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2K - Toss Table of Contents into file 2

Status
Not open for further replies.

logius

Programmer
Aug 30, 2001
175
US
I'd asked this earlier, but the answer I got wasn't very insightful, and the person ignored requests for clarification. What I need is a macro to take the Table of Contents from a Word 2000 file and save them into a .CSV file (with each entry as a separate cell). I've never worked with macros in Word before, so, please, be nice. :p
 
Well, CSV files don't have "cells". CSV means comma-separated values.

Here's your code:

Sub MakeCSV()
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteSpecial DataType:=wdPasteText
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2
Selection.Rows.ConvertToText Separator:=wdSeparateByCommas
ActiveDocument.SaveAs FileName:="mycsvfile.csv", FileFormat:=wdFormatText
ActiveWindow.Close
End Sub

Change the name of "mycsvfile.csv" to the name you want it to be.
Brainbench MVP for Microsoft Word
techsupportgirl@home.com
 
Hey Dreamboat. Word Exposes the table of contents as an object. Perhaps adding the following to your code would work.

Sub MakeCSV()
Dim myTOC As TableOfContents
Set myTOC = ActiveDocument.TablesOfContents(1)
myTOC.Range.Select

Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteSpecial DataType:=wdPasteText
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2
Selection.Rows.ConvertToText Separator:=wdSeparateByCommas
ActiveDocument.SaveAs FileName:="mycsvfile.csv", FileFormat:=wdFormatText
ActiveWindow.Close
End Sub

Tyrone Lumley
augerinn@gte.net
 
Y'all BOTH get stars for this one! :-D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top