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 derfloh 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
Joined
Aug 30, 2001
Messages
175
Location
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
 
Go for it, Tyrone! I'm a recorder at heart. I don't WRITE code, LOL, I'm still recording and editing it. My husband and I like to joke around about all that Dim Sum stuff like so much chinese food. LOL Brainbench MVP for Microsoft Word
techsupportgirl@home.com
 
Y'all BOTH get stars for this one! :-D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top