Compiling a doc with sections from another doc based on some param

A

Akhare

COuld anyone help me on the following problem I am facing?

I have a main document which contains multiple sections. I want to create a
copy of this document only with certain sections of the main document. This
is based on some parameter which I pass. I want to create another copy with
some other sections of the main document again based on some parameter that I
can pass.

In brief, I want to programmatically compile sections of a main document
into another document based on some parameter.

Thanks for any help that is forthcoming.
 
D

Doug Robbins - Word MVP

Without knowing the parameter, it is hard to give specific information.
However, if you constructed an Array containing the Section numbers of the
Sections that met the Parameter, you could substitute those arrays for the
Doc1 arrays in the following which creates one document containing the odd
numbered sections from the source document and another that contains the
even numbered sections from the source document.

Dim Source As Document, Target1 As Document, Target2 As Document
Dim Doc1 As Variant
Set Source = ActiveDocument

Doc1 = Split("1/3/5/7", "/")
Set Target1 = Documents.Add
For i = 0 To UBound(Doc1)
Target1.Range.InsertAfter Source.Sections(Doc1(i)).Range
Next i
Doc1 = Split("2/4/6", "/")
Set Target2 = Documents.Add
For i = 0 To UBound(Doc1)
Target2.Range.InsertAfter Source.Sections(Doc1(i)).Range
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
A

Akhare

Hello Doug

Thanks for your quick response.

The sections in the document correspond to specific features of a software.
From the main document I would like to create a document based on parameter
'Basic', it should copy only certain sections which have been defined as
'Basic' (I do not know how I can define the sections as Basic or Advanced').
If I want Advanced, the document should only copy sections which have been
defined as Advanced.

I know this seems to be very complicated. Could you please help me with this?

Thanks and Regards
Alka
 
G

Graham Mayor

Doug's macro will already do that with a minor modification. All you need to
do is establish which sections (separated by section breaks) of your source
document apply to Basic and which to Advanced and set the two arrays -
Doc1 = Split("1/3/5/7", "/")
to include those section numbers. In the above example the document uses
sections 1,3,5 & 7.
The order of the numbers reflects the order of the sections as they are to
be used. You can use any combination that exists in your source document in
any order (even duplicated) eg
Doc1 = Split("4/3/5/4/7/1", "/")
in either array.

The macro could then be

Sub AssembleDoc()
Dim Source As Document, Target1 As Document
Dim sBasic As String
Dim Doc1 As Variant
Set Source = ActiveDocument
bBasic = MsgBox("For Basic spec. choose Yes," & vbCr & _
"otherwise Choose No", _
vbYesNo, "Create Document")
If bBasic = vbYes Then
Doc1 = Split("1/3/5/7", "/")
Else
Doc1 = Split("2/4/6", "/")
End If
Set Target1 = Documents.Add
For i = 0 To UBound(Doc1)
Target1.Range.InsertAfter Source.Sections(Doc1(i)).Range
Next i
End Sub

For alternative approaches - see http://www.gmayor.com/SelectFile.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top