Avatar of forumware
forumware
 asked on

Extract particular section from word files

I have about 100 word (Doc, docx) files and need to extract a particular section. 2.9: Address. This "section" is in the Table of Contents as well as within the document.  How can i find and extract this section using vba, macro or python etc.
Microsoft WordVisual Basic ClassicProgramming

Avatar of undefined
Last Comment
Anastasia D. Gavanas

8/22/2022 - Mon
GrahamSkan

Presumably the 'section' begins with an automatically-numbered Heading 2 paragraph with the text "Address". What defines the section end?
forumware

ASKER
The next section also starts with Heading 2 but varies, some is general information, interconnections, logical diagrams.
SOLUTION
Anastasia D. Gavanas

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
GrahamSkan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Anastasia D. Gavanas

forumware, let us know about GrahamSkan's macro, I think it will work just fine :)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
forumware

ASKER
Thanks to both, will give it a try shortly. I forgot to mention that I wanted to extract this information to a csv instead of another word document.
SOLUTION
Anastasia D. Gavanas

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
GrahamSkan

xtermie is right. There is no built-in procedure to export a Word document to a CSV file. It does exist in Excel and Access because those applications deal exclusively with data in a table format.
The new task, therefore is to fit the data to a table. Then it can be converted to comma-separated text and saved as a text file.
Anastasia D. Gavanas

Graham, I think it would it be easier to copy-paste the particular text into an Excel file and then save the Excel file in a .csv format. What do you think?  If we change that in your macro, everything should work exactly as forumware wants.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
GrahamSkan

xtermie,
Sorry, I'm a few hours behind you.
Yes, that seems like a good idea.
GrahamSkan

We would need to know the rules for splitting the text into fields (columns) - by words, sentences, paragraphs or something else.
forumware

ASKER
All apologies on the delay. I've tried running the script and get Run time error '5174'

This file could not be found. But i see it listed in the c:\test directory.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Anastasia D. Gavanas

Check if it is .docx or .doc
If it is .doc change script accordingly
forumware

ASKER
Did that, left one DOCX in c:\test and got the same runtime error.
GrahamSkan

Which line does it fail on?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Anastasia D. Gavanas

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
GrahamSkan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Anastasia D. Gavanas

experts provided solid collaborative working solution to author