That suggests that the three original documents are not quite as you
described them. The macro code is quite specific. Without the
original documents, I would be fishing in the dark to correct it.
Are you able to send me the thee documents? If so, zip them up and
send them to the link on the home page of my web site.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Bhavana wrote:
Sir,
As advised by you I have made necessary changes. code is working
fine but at the end all the six final documents created by system
goes blank.
You will get an error unless you change the path to where you have
stored the three documents and unless the documents are named "Q
Set
1.docx", "Q Set 2.docx" and "Q Set 3.docx" as I explained!
Howeevr thanks to premature wrapping of the line in forum editor
the line should actually read
Set QDoc = Documents.Open("D:\My Documents\Test\Versions\Even\Q
Set" & i & ".docx")
as this will probably wrap incorrectly too, maybe the following
will help
Set QDoc = Documents.Open("D:\Path\Q Set " & i & ".docx")
D:\Path should be changed to the path where you have stored the 3
documents.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Bhavana wrote:
Thank you sir for your prompt response.
I am getting runtime error 5174 that at the given path file not
found. I have saved all the three original files as per given
path. Am I suppose to give question set no.
Set QDoc = Documents.Open("D:\My Documents\Test\Versions\Even\Q
Set " _ & i & ".docx")
Sir where I am going wrong ??
The following macro should do what you ask, provided your 3
documents are laid out as you indicated.
The macro assumes that the three original documents are named
with the number being used to select the document
Q Set 1.docx
Q Set 2.docx
Q Set 3.docx
and the path used is "D:\My Documents\Test\Versions\Even\"
It will also work with doc format as long as you change the
extension in the line
Set QDoc = Documents.Open("D:\My Documents\Test\Versions\Even\Q
Set " _ & i & ".docx")
The macro produces 6 question papers named Test1 to 6.docx
again you can use doc format if you make the necessary changes.
The original documents are not affected and the macro finishes
with the six documents open.
The code can undoubtedly be simplified if you want to put the
time into doing so, but it works as is.
Sub CreateQuestionsPapers()
Dim QDoc As Document
Dim TDoc1 As Document
Dim TDoc2 As Document
Dim TDoc3 As Document
Dim TDoc4 As Document
Dim TDoc5 As Document
Dim TDoc6 As Document
Dim oRng As Range
Dim qRng As Range
Dim QNum As Long
Dim Count As Long
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
Set TDoc1 = Documents.Add
Set TDoc2 = Documents.Add
Set TDoc3 = Documents.Add
Set TDoc4 = Documents.Add
Set TDoc5 = Documents.Add
Set TDoc6 = Documents.Add
Dim NewDocs As Variant
For i = 3 To 1 Step -1
Count = 0
Set QDoc = Documents.Open("D:\My
Documents\Test\Versions\Even\Q Set " _ & i & ".docx")
With Selection
.EndKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
While .Execute(findText:="Q.*", _
MatchWildcards:=True, _
Forward:=False)
Set oRng = Selection.Range
Count = Count + 1
Select Case Count
Case Is = 1, 2, 3, 4, 5
TDoc6.Range.InsertBefore oRng
Case Is = 6, 7, 8, 9, 10
TDoc5.Range.InsertBefore oRng
Case Is = 11, 12, 13, 14, 15
TDoc4.Range.InsertBefore oRng
Case Is = 16, 17, 18, 19, 20
TDoc3.Range.InsertBefore oRng
Case Is = 21, 22, 23, 24, 25
TDoc2.Range.InsertBefore oRng
Case Is = 26, 27, 28, 29, 30
TDoc1.Range.InsertBefore oRng
End Select
oRng.Collapse wdCollapseStart
Wend
End With
End With
QDoc.Close wdDoNotSaveChanges
Next i
With TDoc6
.Activate
With Selection
.HomeKey wdStory
QNum = 0
While .Find.Execute("Q.[0-9]{1,2}", _
Replacewith:="Q.", _
MatchWildcards:=True, _
Forward:=True, _
Wrap:=wdFindStop)
QNum = QNum + 1
Set qRng = Selection.Range
qRng.InsertAfter QNum & " "
Selection.Collapse wdCollapseEnd
Wend
End With
.SaveAs "Test6.docx"
End With
With TDoc5
.Activate
With Selection
.HomeKey wdStory
QNum = 0
While .Find.Execute("Q.[0-9]{1,2}", _
Replacewith:="Q.", _
MatchWildcards:=True, _
Forward:=True, _
Wrap:=wdFindStop)
QNum = QNum + 1
Set qRng = Selection.Range
qRng.InsertAfter QNum & " "
Selection.Collapse wdCollapseEnd
Wend
End With
.SaveAs "Test5.docx"
End With
With TDoc4
.Activate
With Selection
.HomeKey wdStory
QNum = 0
While .Find.Execute("Q.[0-9]{1,2}", _
Replacewith:="Q.", _
MatchWildcards:=True, _
Forward:=True, _
Wrap:=wdFindStop)
QNum = QNum + 1
Set qRng = Selection.Range
qRng.InsertAfter QNum & " "
Selection.Collapse wdCollapseEnd
Wend
End With
.SaveAs "Test4.docx"
End With
With TDoc3
.Activate
With Selection
.HomeKey wdStory
QNum = 0
While .Find.Execute("Q.[0-9]{1,2}", _
Replacewith:="Q.", _
MatchWildcards:=True, _
Forward:=True, _
Wrap:=wdFindStop)
QNum = QNum + 1
Set qRng = Selection.Range
qRng.InsertAfter QNum & " "
Selection.Collapse wdCollapseEnd
Wend
End With
.SaveAs "Test3.docx"
End With
With TDoc2
.Activate
With Selection
.HomeKey wdStory
QNum = 0
While .Find.Execute("Q.[0-9]{1,2}", _
Replacewith:="Q.", _
MatchWildcards:=True, _
Forward:=True, _
Wrap:=wdFindStop)
QNum = QNum + 1
Set qRng = Selection.Range
qRng.InsertAfter QNum & " "
Selection.Collapse wdCollapseEnd
Wend
End With
.SaveAs "Test2.docx"
End With
With TDoc1
.Activate
With Selection
.HomeKey wdStory
QNum = 0
While .Find.Execute("Q.[0-9]{1,2}", _
Replacewith:="Q.", _
MatchWildcards:=True, _
Forward:=True, _
Wrap:=wdFindStop)
QNum = QNum + 1
Set qRng = Selection.Range
qRng.InsertAfter QNum & " "
Selection.Collapse wdCollapseEnd
Wend
End With
.SaveAs "Test1.docx"
End With
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Bhavana wrote:
Sir,
The first 5 questions from each file. for eg. 1st set will be
1st five questions from each file 2nd set will be the next 5
questions i.e. question no.6 to 10 from each file & so on.
In this example I want particilar selection i.e. asending
order. Yes I want them inserted subjectwise questions only in word
document as I have another software to change questions order
by system itself once I make it online.
Renumbering will be added advantage.
bhavana
You have three files each with 30 questions and their answers
- 90 questions - laid out as your example and numbered,
presumably, Q1 to Q30? You want to select 5 questions from
each of the three files and create a new document containing
15 questions, and their answers? The burning question is
*which* five questions from each file?
Do you want a particular selection or a random selection?
Do you want them inserted in the order they appear in the
files? Which order do you want to process the files in?
Will you then want the questions renumbering from 1 to 15?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Bhavana wrote:
I have three different word files on different topics with 30