Macro to Make List in Word 2003

W

wmmacro

I am trying to write a macro that would find any word in a document in
quotation marks, ie, "Data" and then take that word and create a list out of
it and any other word in quotations at the bottom of a document. Could
someone help me write that macro? I am a newbie to writing macros and would
appreciate any help I could get.
 
P

Pesach Shelnitz

Hi,

The following macro uses a wildcard search on a Range object to find single
words in quotation marks. Note that the search also finds words that contain
an apostrophe. The macro adds each word to a list that it inserts at the end
of the document.

Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String

Set myRange = ActiveDocument.Range
myString = ""
With myRange
.start = 0
Do While .Find.Execute(FindText:="^34[A-Za-z']{1,}^34", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> "" Then
ActiveDocument.Bookmarks("\EndOfDoc").Select
Selection.TypeText vbCrLf & "Words in quotation marks" _
& vbCrLf & myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub
 
W

wmmacro

Thanks for your quick reply. I pasted this macro into my VBA and then ran it
in a document that only had a sentence, in which there were several words in
quotes. However, it came back with your message "No words in quotation marks
were found." Do you know why this is? Do I have to modify the macro in
anyway? I'm sorry, I'm totally new to this.

Pesach Shelnitz said:
Hi,

The following macro uses a wildcard search on a Range object to find single
words in quotation marks. Note that the search also finds words that contain
an apostrophe. The macro adds each word to a list that it inserts at the end
of the document.

Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String

Set myRange = ActiveDocument.Range
myString = ""
With myRange
.start = 0
Do While .Find.Execute(FindText:="^34[A-Za-z']{1,}^34", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> "" Then
ActiveDocument.Bookmarks("\EndOfDoc").Select
Selection.TypeText vbCrLf & "Words in quotation marks" _
& vbCrLf & myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub

--
Hope this helps,
Pesach Shelnitz


wmmacro said:
I am trying to write a macro that would find any word in a document in
quotation marks, ie, "Data" and then take that word and create a list out of
it and any other word in quotations at the bottom of a document. Could
someone help me write that macro? I am a newbie to writing macros and would
appreciate any help I could get.
 
P

Peter T. Daniels

It looks like the macro will only find straight-quotes (^34), not
curly-quotes.

Thanks for your quick reply.  I pasted this macro into my VBA and then ran it
in a document that only had a sentence, in which there were several wordsin
quotes.  However, it came back with your message "No words in quotationmarks
were found."  Do you know why this is?  Do I have to modify the macroin
anyway?  I'm sorry, I'm totally new to this.



Pesach Shelnitz said:
The following macro uses a wildcard search on a Range object to find single
words in quotation marks. Note that the search also finds words that contain
an apostrophe. The macro adds each word to a list that it inserts at the end
of the document.
Sub ListWordsInQuotes()
    Dim myRange As Range
    Dim myString As String
    Set myRange = ActiveDocument.Range
    myString = ""
    With myRange
        .start = 0
        Do While .Find.Execute(FindText:="^34[A-Za-z']{1,}^34", _
                MatchWildcards:=True, _
                Wrap:=wdFindStop, Forward:=True) = True
            .MoveStart Unit:=wdCharacter, Count:=1
            .MoveEnd Unit:=wdCharacter, Count:=-1
            myString = myString & .Text & vbCrLf
            .Collapse Direction:=wdCollapseEnd
        Loop
    End With
    If myString <> "" Then
        ActiveDocument.Bookmarks("\EndOfDoc").Select
        Selection.TypeText vbCrLf & "Words in quotation marks" _
        & vbCrLf & myString
    Else
        MsgBox "No words in quotation marks were found."
    End If
    Set myRange = Nothing
End Sub
"wmmacro" wrote:

- Show quoted text -
 
G

Greg Maxey

Peter is correct but offers little help in the way of a solution :-(.

Try:

Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String
Set myRange = ActiveDocument.Range
myString = vbCr & "Words in quotation marks." & vbCr
With myRange
Do While
..Find.Execute(FindText:="[^0147^01486^34][A-Za-z']{1,}[^0147^01486^34]", _
MatchWildcards:=True, Wrap:=wdFindStop,
Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> vbCr & "Words in quotation marks." & vbCr Then
ActiveDocument.Range.InsertAfter myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub

Note: This code only finds words in quotations marks that are located in
the main text storyrange of the document. Additional code and loops are
required if you are interested in find text in areas such as
headers/footers, textboxes, etc.





--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org



It looks like the macro will only find straight-quotes (^34), not
curly-quotes.

Thanks for your quick reply. I pasted this macro into my VBA and then ran
it
in a document that only had a sentence, in which there were several words
in
quotes. However, it came back with your message "No words in quotation
marks
were found." Do you know why this is? Do I have to modify the macro in
anyway? I'm sorry, I'm totally new to this.



Pesach Shelnitz said:
The following macro uses a wildcard search on a Range object to find
single
words in quotation marks. Note that the search also finds words that
contain
an apostrophe. The macro adds each word to a list that it inserts at the
end
of the document.
Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String
Set myRange = ActiveDocument.Range
myString = ""
With myRange
.start = 0
Do While .Find.Execute(FindText:="^34[A-Za-z']{1,}^34", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> "" Then
ActiveDocument.Bookmarks("\EndOfDoc").Select
Selection.TypeText vbCrLf & "Words in quotation marks" _
& vbCrLf & myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub
"wmmacro" wrote:

- Show quoted text -
 
P

Peter T. Daniels

My solution, which I knew Greg would plotz over, would simply be to
replace the curly-quotes with straight-quotes (and re-replace them at
the end, if necessary).

But hey, Greg has a hammer, so everything looks like a nail to him.

Peter is correct but offers little help in the way of a solution :-(.

Try:

Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String
Set myRange = ActiveDocument.Range
myString = vbCr & "Words in quotation marks." & vbCr
With myRange
  Do While
.Find.Execute(FindText:="[^0147^01486^34][A-Za-z']{1,}[^0147^01486^34]", _
                         MatchWildcards:=True, Wrap:=wdFindStop,
Forward:=True) = True
    .MoveStart Unit:=wdCharacter, Count:=1
    .MoveEnd Unit:=wdCharacter, Count:=-1
    myString = myString & .Text & vbCrLf
    .Collapse Direction:=wdCollapseEnd
  Loop
End With
If myString <> vbCr & "Words in quotation marks." & vbCr Then
  ActiveDocument.Range.InsertAfter myString
Else
  MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub

Note:  This code only finds words in quotations marks that are located in
the main text storyrange of the document.  Additional code and loops are
required if you are interested in find text in areas such as
headers/footers, textboxes, etc.

--
Greg Maxey -  Word MVP

My web sitehttp://gregmaxey.mvps.org
Word MVP web sitehttp://word.mvps.org

It looks like the macro will only find straight-quotes (^34), not
curly-quotes.

Thanks for your quick reply. I pasted this macro into my VBA and then ran
it
in a document that only had a sentence, in which there were several words
in
quotes. However, it came back with your message "No words in quotation
marks
were found." Do you know why this is? Do I have to modify the macro in
anyway? I'm sorry, I'm totally new to this.
Pesach Shelnitz said:
Hi,
The following macro uses a wildcard search on a Range object to find
single
words in quotation marks. Note that the search also finds words that
contain
an apostrophe. The macro adds each word to a list that it inserts at the
end
of the document.
Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String
Set myRange = ActiveDocument.Range
myString = ""
With myRange
.start = 0
Do While .Find.Execute(FindText:="^34[A-Za-z']{1,}^34", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> "" Then
ActiveDocument.Bookmarks("\EndOfDoc").Select
Selection.TypeText vbCrLf & "Words in quotation marks" _
& vbCrLf & myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub
--
Hope this helps,
Pesach Shelnitz
:
I am trying to write a macro that would find any word in a documentin
quotation marks, ie, "Data" and then take that word and create a list
out of
it and any other word in quotations at the bottom of a document. Could
someone help me write that macro? I am a newbie to writing macros and
would
appreciate any help I could get.-
 
G

Greg Maxey

If you had a solution then why didn't you offer it? And why are you now
leaving the OP to perhaps wonder how to replace curly quotes with straight
quotes?

Back to point:

If you don't know the answer, it is ok to leave the question to those who
do.

My solution, which I knew Greg would plotz over, would simply be to
replace the curly-quotes with straight-quotes (and re-replace them at
the end, if necessary).

But hey, Greg has a hammer, so everything looks like a nail to him.

Peter is correct but offers little help in the way of a solution :-(.

Try:

Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String
Set myRange = ActiveDocument.Range
myString = vbCr & "Words in quotation marks." & vbCr
With myRange
Do While
.Find.Execute(FindText:="[^0147^01486^34][A-Za-z']{1,}[^0147^01486^34]",
_
MatchWildcards:=True, Wrap:=wdFindStop,
Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> vbCr & "Words in quotation marks." & vbCr Then
ActiveDocument.Range.InsertAfter myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub

Note: This code only finds words in quotations marks that are
located in
the main text storyrange of the document. Additional code and loops
are
required if you are interested in find text in areas such as
headers/footers, textboxes, etc.

--
Greg Maxey - Word MVP

My web sitehttp://gregmaxey.mvps.org
Word MVP web sitehttp://word.mvps.org

messageIt looks like the macro will only find straight-quotes (^34), not
curly-quotes.

Thanks for your quick reply. I pasted this macro into my VBA and
then ran it
in a document that only had a sentence, in which there were several
words in
quotes. However, it came back with your message "No words in
quotation marks
were found." Do you know why this is? Do I have to modify the macro
in anyway? I'm sorry, I'm totally new to this.
The following macro uses a wildcard search on a Range object to
find single
words in quotation marks. Note that the search also finds words
that contain
an apostrophe. The macro adds each word to a list that it inserts
at the end
of the document.
Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String
Set myRange = ActiveDocument.Range
myString = ""
With myRange
.start = 0
Do While .Find.Execute(FindText:="^34[A-Za-z']{1,}^34", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> "" Then
ActiveDocument.Bookmarks("\EndOfDoc").Select
Selection.TypeText vbCrLf & "Words in quotation marks" _
& vbCrLf & myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub
"wmmacro" wrote:
I am trying to write a macro that would find any word in a
document in quotation marks, ie, "Data" and then take that word
and create a list out of
it and any other word in quotations at the bottom of a document.
Could someone help me write that macro? I am a newbie to writing
macros and would
appreciate any help I could get.-
 
P

Peter T. Daniels

(a) Because pointing out what the problem was makes the solution
obvious.

(b) Because I don't assume OP is an idiot. Not being able to create or
debug a macro doesn't make one an incompetent Word user.

Having as one's only skill the creating and debugging of macros
doesn't make one a competent Word user.

If you had a solution then why didn't you offer it?  And why are you now
leaving the OP to perhaps wonder how to replace curly quotes with straight
quotes?

Back to point:

If you don't know the answer, it is ok to leave the question to those who
do.
My solution, which I knew Greg would plotz over, would simply be to
replace the curly-quotes with straight-quotes (and re-replace them at
the end, if necessary).
But hey, Greg has a hammer, so everything looks like a nail to him.
Peter is correct but offers little help in the way of a solution :-(.
Try:
Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String
Set myRange = ActiveDocument.Range
myString = vbCr & "Words in quotation marks." & vbCr
With myRange
Do While
.Find.Execute(FindText:="[^0147^01486^34][A-Za-z']{1,}[^0147^01486^34]",
_
MatchWildcards:=True, Wrap:=wdFindStop,
Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> vbCr & "Words in quotation marks." & vbCr Then
ActiveDocument.Range.InsertAfter myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub
Note: This code only finds words in quotations marks that are
located in
the main text storyrange of the document. Additional code and loops
are
required if you are interested in find text in areas such as
headers/footers, textboxes, etc.
--
Greg Maxey - Word MVP
My web sitehttp://gregmaxey.mvps.org
Word MVP web sitehttp://word.mvps.org
messageIt looks like the macro will only find straight-quotes (^34), not
curly-quotes.
Thanks for your quick reply. I pasted this macro into my VBA and
then ran it
in a document that only had a sentence, in which there were several
words in
quotes. However, it came back with your message "No words in
quotation marks
were found." Do you know why this is? Do I have to modify the macro
in anyway? I'm sorry, I'm totally new to this.
:
Hi,
The following macro uses a wildcard search on a Range object to
find single
words in quotation marks. Note that the search also finds words
that contain
an apostrophe. The macro adds each word to a list that it inserts
at the end
of the document.
Sub ListWordsInQuotes()
Dim myRange As Range
Dim myString As String
Set myRange = ActiveDocument.Range
myString = ""
With myRange
.start = 0
Do While .Find.Execute(FindText:="^34[A-Za-z']{1,}^34", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
.MoveStart Unit:=wdCharacter, Count:=1
.MoveEnd Unit:=wdCharacter, Count:=-1
myString = myString & .Text & vbCrLf
.Collapse Direction:=wdCollapseEnd
Loop
End With
If myString <> "" Then
ActiveDocument.Bookmarks("\EndOfDoc").Select
Selection.TypeText vbCrLf & "Words in quotation marks" _
& vbCrLf & myString
Else
MsgBox "No words in quotation marks were found."
End If
Set myRange = Nothing
End Sub
--
Hope this helps,
Pesach Shelnitz
:
I am trying to write a macro that would find any word in a
document in quotation marks, ie, "Data" and then take that word
and create a list out of
it and any other word in quotations at the bottom of a document.
Could someone help me write that macro? I am a newbie to writing
macros and would
appreciate any help I could get.-
 

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