PDA

View Full Version : Extract contents of Headings to new document



sampath_123
02-14-2009, 12:30 PM
hi all

I am new to this forum I am searching for a macro which takes the Heading name as input and Exports the contents of the heading into a new word document I am new to Macros but it is extremely important for me plzzzzzz help me.

lucas
02-14-2009, 12:51 PM
Sounds like you might need to use a template. Can you post an example with a few details......a little more on why you need to export just the heading? What if there are more than one line that is a heading? You're not confusing heading with header are you?

post reply-scroll down and look for "manage attachments"

sampath_123
02-14-2009, 01:01 PM
This is the Template that I have

[Heading 1]

Contents go here

[Heading 2]

Contents go here


I need to export these contents to a new word document because my job involves in reading only specific sections of word document it would be great help if the process is automated

I have been trying around to do this but its not working
Plzz Help

sampath_123
02-14-2009, 10:14 PM
hi

This is Template that i am working on I want only specific sections to be extracted to seperate document

Thanks

Sampath

lucas
02-15-2009, 08:44 AM
Hi Sampath, I would like to ask you to read our faq. PM's to posters asking for help with this is wasted effort and annoying and violates the terms for using our forum. Please read this, specifically the part about pm's:

http://www.vbaexpress.com/forum/faq.php?faq=psting_faq_item#faq_req_help_pm

I would advise that you read our entire FAQ before posting again.

Additionally, posting this very same question in the ms project forum today has caused me to spend time deleting that duplicate post in an inappropriate forum..........time I might have spent looking at your problem.

In short, you have caused me to spend the little time I have for the forum, chasing down your inappropriate posts and pm's........

This will not get you a faster response or put you at the top of the list for help......

We are glad to have new members but you should take a little time to learn how things are done before diving in and making things hard for everyone.

lucas
02-15-2009, 08:45 AM
You say you only want specific sections. You should probably identify those sections or indicate how we might be able to identify them......

sampath_123
02-15-2009, 06:39 PM
I am sorry for that LUCAS i will not repeat it again.In above template I want to extract the contents of
Data access

Non-functional Requirements

Extension Points

These always vary from document to document
Thanks

fumei
02-16-2009, 12:16 PM
sampath_123, the very fact that "these" vary from document to document (which is not surprising) is the issue.

You need to identify those parts.

How?

Well, there are ways. However, until you (or whoever is creating these documents) truly understands and uses Word properly, I think it would be a waste of time to try and suggest a way for you. This is a conceptual problem, not a terribly difficult problem.

In other words, IF your document used Word properly, then what you are asking for would be quite easy to do. I do that sort of thing often.

But your document does not use Word properly, therefore to do what you ask is difficult.

BTW: you may call your attachment a template, but it is not a template.

fumei
02-16-2009, 01:05 PM
Sorry, I did not want to sounds brusque. Here is one way. It is hard to say what will work as you do not give full details - for example, you want to include the heading ("Data Access"), or not.

1. use a real template
2. bookmark your headings ("Data Access")
3. write a Sub that collects those bookmark Start and End numbers
4. declare a Range object that uses those values. In other words:

Dim CopyRange As Range
Set CopyRange = ActiveDocument.Range( _
.Start:= ActiveDocument.Bookmarks("DataAccess").Range.End + 1, _
.End:=ActiveDocument.Bookmarks("NonFunctional").Range.Start - 1
CopyRange.Copy
Documents.Add
ActiveDocument.Range.Paste
' save it? with what name?
This creates a range object that covers the range between the .End of the DataAccess bookmark, and the .Start of the NonFunctional bookmark.

The range is copied, a new document created, the range contents are pasted into the new document.

Done.

It makes no difference if that is one page, one paragraph, or fifteen pages.

sampath_123
02-17-2009, 10:52 AM
hi Thanks for your help I have tried to implement your logic but i am getting a run time Error :"Requested member of the collection does not Exists
I have checked for my book marks they are all pretty fine

Here is my code

Sub Macro1()
Dim oFF As FormField
Dim DocFF As FormFields
Dim r As Range
Dim rng As Range
Dim CopyRange As Range
Dim msg As String
Set DocB = Word.Documents.Add
With DocB.PageSetup
.TopMargin = InchesToPoints(0.25)
.BottomMargin = InchesToPoints(0.25)
.LeftMargin = InchesToPoints(0.25)
.RightMargin = InchesToPoints(0.25)
End With
Set DocA = ActiveDocument
Set rng = DocB.Range
With CopyRange
Set CopyRange = ActiveDocument.Range( _
Start:=ActiveDocument.Bookmarks("Includes").Range.Start, _
End:=ActiveDocument.Bookmarks("Triggers").Range.End - 8)
End With
CopyRange.Copy
Documents.Add
ActiveDocument.Range.Paste
MsgBox ActiveDocument.Range.Text
DocA.Close Savechanges:=wdDoNotSaveChanges
Set DocA = Nothing
MsgBox "Done creating new document with headings only."
End Sub


please help me out

fumei
02-17-2009, 11:52 AM
Methinks you need to do some research on what objects are, and how to use them.

Hint: how do you think you can use a With something...when you have not actually got that something yet????

If you do not actually have something yet...then that something..."does not exist". The error is quite correct. The object you are trying to use does not exist.

BTW: please use the code tags for when posting code.

lucas
02-17-2009, 04:56 PM
If you used Option explicit at the top of the code module you would also know that some of the variables are not defined.

fumei
02-18-2009, 09:58 AM
Yes. That is good advice. sampath_123, I would second that. Use Option Explicit.