Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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" 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. |
#3
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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" wrote: 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" 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. |
#4
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
It looks like the macro will only find straight-quotes (^34), not
curly-quotes. On Aug 6, 2:48*pm, wmmacro wrote: 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" wrote: 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" 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.- Hide quoted text - - Show quoted text - |
#5
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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 Word MVP web site http://word.mvps.org "Peter T. Daniels" wrote in message ... It looks like the macro will only find straight-quotes (^34), not curly-quotes. On Aug 6, 2:48 pm, wmmacro wrote: 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" wrote: 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" 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.- Hide quoted text - - Show quoted text - |
#6
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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. On Aug 6, 8:00*pm, "Greg Maxey" wrote: 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 "Peter T. Daniels" wrote in ... It looks like the macro will only find straight-quotes (^34), not curly-quotes. On Aug 6, 2:48 pm, wmmacro wrote: 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" wrote: 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" 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.- |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
ISO macro to make an index list of defined terms | Formatting Long Documents | |||
How do I make a macro available every time I open Word? | Microsoft Word Help | |||
How do I make a list of people from an *.mdb recipients list | Mailmerge | |||
Word Macro, List Commands is missing | Microsoft Word Help | |||
How to make list of names & addresses to list of mailing labels? | Microsoft Word Help |