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.-