How do I locate capitalized words in a doc?

C

caj3000

I'm trying to streamline the creation of an index. Ideally, I would like to
pull all capitalized words from a document to a comma delimited file for a
concordance table. (Wishful thinking?) Thank you so much.
 
G

Greg Maxey

Not so elegant and the comma delimited file part is up to you, but this
should help get you started:

Sub ScratchMacro()
Dim oWord As Word.Range
Dim pStr As String
For Each oWord In ActiveDocument.Range.Words
If oWord.Characters.First Like "[A-Z]" Then
pStr = pStr & "," & Trim(oWord)
End If
Next oWord
MsgBox Right(pStr, Len(pStr) - 1)
End Sub
 
C

caj3000

Thank you! However, the results are appear in a truncated grey box that I
cannot copy from. Am I missing something?
Thx.

Greg Maxey said:
Not so elegant and the comma delimited file part is up to you, but this
should help get you started:

Sub ScratchMacro()
Dim oWord As Word.Range
Dim pStr As String
For Each oWord In ActiveDocument.Range.Words
If oWord.Characters.First Like "[A-Z]" Then
pStr = pStr & "," & Trim(oWord)
End If
Next oWord
MsgBox Right(pStr, Len(pStr) - 1)
End Sub


--
Greg Maxey - Word MVP

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



caj3000 said:
I'm trying to streamline the creation of an index. Ideally, I would like
to
pull all capitalized words from a document to a comma delimited file for a
concordance table. (Wishful thinking?) Thank you so much.
 
G

Greg Maxey

Try this:

Sub ScratchMacro()
Dim oWord As Word.Range
Dim pStr As String
Dim oDoc As Word.Document
Dim oDoc2 As Word.Document
Set oDoc = ThisDocument
Set oDoc2 = Documents.Add
For Each oWord In oDoc.Range.Words
If oWord.Characters.First Like "[A-Z]" Then
pStr = pStr & "," & Trim(oWord)
End If
Next oWord
oDoc2.Range.InsertAfter Right(pStr, Len(pStr) - 1)
End Sub
Thank you! However, the results are appear in a truncated grey box
that I cannot copy from. Am I missing something?
Thx.

Greg Maxey said:
Not so elegant and the comma delimited file part is up to you, but
this should help get you started:

Sub ScratchMacro()
Dim oWord As Word.Range
Dim pStr As String
For Each oWord In ActiveDocument.Range.Words
If oWord.Characters.First Like "[A-Z]" Then
pStr = pStr & "," & Trim(oWord)
End If
Next oWord
MsgBox Right(pStr, Len(pStr) - 1)
End Sub


--
Greg Maxey - Word MVP

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



caj3000 said:
I'm trying to streamline the creation of an index. Ideally, I would
like to
pull all capitalized words from a document to a comma delimited
file for a concordance table. (Wishful thinking?) Thank you so much.
 
C

caj3000

PERFECT!! Thank you SO much!

Greg Maxey said:
Try this:

Sub ScratchMacro()
Dim oWord As Word.Range
Dim pStr As String
Dim oDoc As Word.Document
Dim oDoc2 As Word.Document
Set oDoc = ThisDocument
Set oDoc2 = Documents.Add
For Each oWord In oDoc.Range.Words
If oWord.Characters.First Like "[A-Z]" Then
pStr = pStr & "," & Trim(oWord)
End If
Next oWord
oDoc2.Range.InsertAfter Right(pStr, Len(pStr) - 1)
End Sub
Thank you! However, the results are appear in a truncated grey box
that I cannot copy from. Am I missing something?
Thx.

Greg Maxey said:
Not so elegant and the comma delimited file part is up to you, but
this should help get you started:

Sub ScratchMacro()
Dim oWord As Word.Range
Dim pStr As String
For Each oWord In ActiveDocument.Range.Words
If oWord.Characters.First Like "[A-Z]" Then
pStr = pStr & "," & Trim(oWord)
End If
Next oWord
MsgBox Right(pStr, Len(pStr) - 1)
End Sub


--
Greg Maxey - Word MVP

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



I'm trying to streamline the creation of an index. Ideally, I would
like to
pull all capitalized words from a document to a comma delimited
file for a concordance table. (Wishful thinking?) Thank you so much.
 
C

caj3000

Greg, I got this to work once, but then it stopped working. The debugger
highlights the last line, the oDoc2 line. Do you have any further
suggestions? Thank you so much.

Greg Maxey said:
Try this:

Sub ScratchMacro()
Dim oWord As Word.Range
Dim pStr As String
Dim oDoc As Word.Document
Dim oDoc2 As Word.Document
Set oDoc = ThisDocument
Set oDoc2 = Documents.Add
For Each oWord In oDoc.Range.Words
If oWord.Characters.First Like "[A-Z]" Then
pStr = pStr & "," & Trim(oWord)
End If
Next oWord
oDoc2.Range.InsertAfter Right(pStr, Len(pStr) - 1)
End Sub
Thank you! However, the results are appear in a truncated grey box
that I cannot copy from. Am I missing something?
Thx.

Greg Maxey said:
Not so elegant and the comma delimited file part is up to you, but
this should help get you started:

Sub ScratchMacro()
Dim oWord As Word.Range
Dim pStr As String
For Each oWord In ActiveDocument.Range.Words
If oWord.Characters.First Like "[A-Z]" Then
pStr = pStr & "," & Trim(oWord)
End If
Next oWord
MsgBox Right(pStr, Len(pStr) - 1)
End Sub


--
Greg Maxey - Word MVP

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



I'm trying to streamline the creation of an index. Ideally, I would
like to
pull all capitalized words from a document to a comma delimited
file for a concordance table. (Wishful thinking?) Thank you so much.
 

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