charliew001
06-05-2012, 07:23 PM
I asked a programmer on another forums to help me write a macro that will select all text that begin with "a." and ends the selection at the first paragraph object after "a." He said the macro should output the desired text into the immediate window but it seems like the only thing outputted is the paragraph object. When I told him this, he told me that I was using a list function to notate the different answers of "a."; "b."; "c."; but I was not. I have a word document with 400+ multiple choice test questions and I want the macro to only select all text that begin with "a." so that I may copy and paste it into an excel chart. I have very little knowledge about programming language, so any help is greatly appreciated.
Please let me know if below code needs to be modified or if anything is wrong.
Sub aselect()
'
' aselect Macro
'
'
Dim pgh As Paragraph, a, i As Integer, sPgh As String
For Each pgh In ThisDocument.Paragraphs
With pgh
sPgh = ""
If Left(.Range.Text, 2) = "a." Then
a = Split(.Range.Text, "a.")
For i = 1 To UBound(a) - 1
sPgh = sPgh & a(i) & "a."
Next
End If
End With
If sPgh <> "" Then _
sPgh = Left(sPgh, Len(sPgh) - 2)
Debug.Print sPgh
Next
End Sub
Please let me know if below code needs to be modified or if anything is wrong.
Sub aselect()
'
' aselect Macro
'
'
Dim pgh As Paragraph, a, i As Integer, sPgh As String
For Each pgh In ThisDocument.Paragraphs
With pgh
sPgh = ""
If Left(.Range.Text, 2) = "a." Then
a = Split(.Range.Text, "a.")
For i = 1 To UBound(a) - 1
sPgh = sPgh & a(i) & "a."
Next
End If
End With
If sPgh <> "" Then _
sPgh = Left(sPgh, Len(sPgh) - 2)
Debug.Print sPgh
Next
End Sub