Macro - numbering the questions ? Need help

B

/-_-b

Hi all,

i'd need help for this particular problem :

I have about 1000 trivia questions and answers in this format :

Question text 1
a) answer 1
b) answer 2
c) answer 3
d) answer 4

Question text 2
a) answer 1
b) answer 2
c) answer 3
d) answer 4

and so on...

The number of the answers by each question vary... sometimes there are 4 and
sometimes 5 answers.

I need to put the numbers in front of the questions like:

1. Question text 1
a)...
....

2. Question text 2
a)...
b)...


Is that doable using the macros ?

Ty all in advance !

Marko
 
J

Jean-Guy Marcil

/-_-b said:
Hi all,

i'd need help for this particular problem :

I have about 1000 trivia questions and answers in this format :

Question text 1
a) answer 1
b) answer 2
c) answer 3
d) answer 4

Question text 2
a) answer 1
b) answer 2
c) answer 3
d) answer 4

and so on...

The number of the answers by each question vary... sometimes there are 4 and
sometimes 5 answers.

I need to put the numbers in front of the questions like:

1. Question text 1
a)...
....

2. Question text 2
a)...
b)...


Is that doable using the macros ?

Ty all in advance !

First clean up your document. (Remove unecessary paragraphs, etc.)
Second, create a style (Named "Question_Number") in my sample code below)
for numbering the questions. This style must include a simple numbering
scheme.
Third run the code.
Fourth, well, nothing, you are done!

This code will apply the "Question_Number" style to all paragraphs that do
not start with "'any character') " (Not Left(.Item(i).Range.Text, 3) Like
"[a-e]) " in the code) and that are not empty (or that do not consit of only
spaces)
(Trim(Left(.Item(i).Range.Text, _
Len(.Item(i).Range.Text) - 1)) in the code).

Option Explicit

Sub NumberQuestion()

Dim i As Long

With ActiveDocument.Paragraphs
For i = 1 To .Count
If (Not Left(.Item(i).Range.Text, 3) Like "[a-e]) ") _
And (Trim(Left(.Item(i).Range.Text, _
Len(.Item(i).Range.Text) - 1))) <> "" Then
.Item(i).Range.Style = "Question_Number"
End If
Next
End With

End Sub
 

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