Script to Capture Data in Document

B

Bilbert

Greetings - Let me say first that at best I consider myself an intermediate
user of MS Office tools and that I am willing to try and learn anything.

I am composing a large document ion Word that requires a list of acronyms,
which are used in the document, to be added at the end. I am not much of a
programmer, but wonder if a script/macro (VBA?) could be written and manually
executed when complete with the document, via a tool bar button from the
template, to scan the document checking for items that have either 3 or 4
uppercase characters enclosed within parentheses. i.e., "(COTS)"

It would then check and capture the 3 or 4 words (which are Title Cap'd)
prior to the open parens and copy it adjacent to the acronym in the table.
i.e., "We use Commercial off-the-Shelf (COTS) applications."

After capturing the data, the macro would list all items in a table and
sort. i.e., "COTS - Commercial off-the-Shelf"

The idea here is to eliminate the need for an editor or author to
continually build a list of items used in the document and to ensure only
items which are used are recorded in the subsequent table.

Any thoughts or suggestions would be greatly appreciated. Thank you in
advance for your assistance. Bill
 
D

Doug Robbins

The following code will do part of what you want - copy from the beginning
of the line on which and Acronym up to the end of the acronym and paste that
string into a new document. You would then of course have to edit out
anything at the beginning of the line that you did not need (or add to it
something that got missed because it was on the previous line). You could
then use find and replace to remove the ) for the text in the new file and
use Convert Text to table selecting the ( as the separator to create a table
containing the definition and its acronym. You can then cut the column
containing the acronyms and paste it in front of the one containing the
definitions.

Dim myrange As Range, Source As Document, Target As Document
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
While .Execute(FindText:="\([A-Z]{2,}\)", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
myrange.Start = myrange.Bookmarks("\line").Range.Start
Target.Range.InsertAfter myrange & vbCr
Wend
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Bilbert

Thank you for your reply Doug, I appreciate it. However, I must confess that
I did not understand it. I probably need to explain it easier and not make it
so complex. I'd just like to scan through a document and build a list of
uppercase items between parens. i.e., (COTS).

Sorry for the confussion. Bill

Doug Robbins said:
The following code will do part of what you want - copy from the beginning
of the line on which and Acronym up to the end of the acronym and paste that
string into a new document. You would then of course have to edit out
anything at the beginning of the line that you did not need (or add to it
something that got missed because it was on the previous line). You could
then use find and replace to remove the ) for the text in the new file and
use Convert Text to table selecting the ( as the separator to create a table
containing the definition and its acronym. You can then cut the column
containing the acronyms and paste it in front of the one containing the
definitions.

Dim myrange As Range, Source As Document, Target As Document
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
While .Execute(FindText:="\([A-Z]{2,}\)", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
myrange.Start = myrange.Bookmarks("\line").Range.Start
Target.Range.InsertAfter myrange & vbCr
Wend
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Bilbert said:
Greetings - Let me say first that at best I consider myself an
intermediate
user of MS Office tools and that I am willing to try and learn anything.

I am composing a large document ion Word that requires a list of acronyms,
which are used in the document, to be added at the end. I am not much of a
programmer, but wonder if a script/macro (VBA?) could be written and
manually
executed when complete with the document, via a tool bar button from the
template, to scan the document checking for items that have either 3 or 4
uppercase characters enclosed within parentheses. i.e., "(COTS)"

It would then check and capture the 3 or 4 words (which are Title Cap'd)
prior to the open parens and copy it adjacent to the acronym in the table.
i.e., "We use Commercial off-the-Shelf (COTS) applications."

After capturing the data, the macro would list all items in a table and
sort. i.e., "COTS - Commercial off-the-Shelf"

The idea here is to eliminate the need for an editor or author to
continually build a list of items used in the document and to ensure only
items which are used are recorded in the subsequent table.

Any thoughts or suggestions would be greatly appreciated. Thank you in
advance for your assistance. Bill
 
D

Doug Robbins

If you just want to create a list of the acronyms at the end of the document
(without their definition), then run the following macro:

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
While .Execute(FindText:="\([A-Z]{2,}\)", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
ActiveDocument.Range.InsertAfter myrange & vbCr
Wend
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Bilbert said:
Thank you for your reply Doug, I appreciate it. However, I must confess
that
I did not understand it. I probably need to explain it easier and not make
it
so complex. I'd just like to scan through a document and build a list of
uppercase items between parens. i.e., (COTS).

Sorry for the confussion. Bill

Doug Robbins said:
The following code will do part of what you want - copy from the
beginning
of the line on which and Acronym up to the end of the acronym and paste
that
string into a new document. You would then of course have to edit out
anything at the beginning of the line that you did not need (or add to it
something that got missed because it was on the previous line). You
could
then use find and replace to remove the ) for the text in the new file
and
use Convert Text to table selecting the ( as the separator to create a
table
containing the definition and its acronym. You can then cut the column
containing the acronyms and paste it in front of the one containing the
definitions.

Dim myrange As Range, Source As Document, Target As Document
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
While .Execute(FindText:="\([A-Z]{2,}\)", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
myrange.Start = myrange.Bookmarks("\line").Range.Start
Target.Range.InsertAfter myrange & vbCr
Wend
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Bilbert said:
Greetings - Let me say first that at best I consider myself an
intermediate
user of MS Office tools and that I am willing to try and learn
anything.

I am composing a large document ion Word that requires a list of
acronyms,
which are used in the document, to be added at the end. I am not much
of a
programmer, but wonder if a script/macro (VBA?) could be written and
manually
executed when complete with the document, via a tool bar button from
the
template, to scan the document checking for items that have either 3 or
4
uppercase characters enclosed within parentheses. i.e., "(COTS)"

It would then check and capture the 3 or 4 words (which are Title
Cap'd)
prior to the open parens and copy it adjacent to the acronym in the
table.
i.e., "We use Commercial off-the-Shelf (COTS) applications."

After capturing the data, the macro would list all items in a table and
sort. i.e., "COTS - Commercial off-the-Shelf"

The idea here is to eliminate the need for an editor or author to
continually build a list of items used in the document and to ensure
only
items which are used are recorded in the subsequent table.

Any thoughts or suggestions would be greatly appreciated. Thank you in
advance for your assistance. Bill
 
D

David Sisson

So let me see if I've got this straight.

You want a table(or list) of the acronyms, seperated by a dash, along
with their long name, at the end of the large document?
Like this...
i.e., "COTS - Commercial off-the-Shelf"

And the long name and the acronym are listed in the document.
Like this...
i.e., "We use Commercial off-the-Shelf (COTS) applications."

Is this correct?
 
A

Art Blondin

Doug Robbins,
Thanks for the code!
Having to work with multiple authors on large technical documents, I can
appreciate what Bill has to deal with. What was really interesting was the
results I got when I tested the Marco on a document I had on hand. The Marco
did everything that you said it would, However, the results were less than
what I expected. So I changed FindText:="\([A-Z]{2,}\)" to
FindText:="[A-Z]{2,}". By removing the (), the Marco listed everything it
found with two or more uppercase letters. This allowed me to see how many
Acronyms were being used but not presented correctly....ART


Doug Robbins said:
If you just want to create a list of the acronyms at the end of the document
(without their definition), then run the following macro:

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
While .Execute(FindText:="\([A-Z]{2,}\)", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
ActiveDocument.Range.InsertAfter myrange & vbCr
Wend
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Bilbert said:
Thank you for your reply Doug, I appreciate it. However, I must confess
that
I did not understand it. I probably need to explain it easier and not make
it
so complex. I'd just like to scan through a document and build a list of
uppercase items between parens. i.e., (COTS).

Sorry for the confussion. Bill

Doug Robbins said:
The following code will do part of what you want - copy from the
beginning
of the line on which and Acronym up to the end of the acronym and paste
that
string into a new document. You would then of course have to edit out
anything at the beginning of the line that you did not need (or add to it
something that got missed because it was on the previous line). You
could
then use find and replace to remove the ) for the text in the new file
and
use Convert Text to table selecting the ( as the separator to create a
table
containing the definition and its acronym. You can then cut the column
containing the acronyms and paste it in front of the one containing the
definitions.

Dim myrange As Range, Source As Document, Target As Document
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
While .Execute(FindText:="\([A-Z]{2,}\)", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
myrange.Start = myrange.Bookmarks("\line").Range.Start
Target.Range.InsertAfter myrange & vbCr
Wend
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Greetings - Let me say first that at best I consider myself an
intermediate
user of MS Office tools and that I am willing to try and learn
anything.

I am composing a large document ion Word that requires a list of
acronyms,
which are used in the document, to be added at the end. I am not much
of a
programmer, but wonder if a script/macro (VBA?) could be written and
manually
executed when complete with the document, via a tool bar button from
the
template, to scan the document checking for items that have either 3 or
4
uppercase characters enclosed within parentheses. i.e., "(COTS)"

It would then check and capture the 3 or 4 words (which are Title
Cap'd)
prior to the open parens and copy it adjacent to the acronym in the
table.
i.e., "We use Commercial off-the-Shelf (COTS) applications."

After capturing the data, the macro would list all items in a table and
sort. i.e., "COTS - Commercial off-the-Shelf"

The idea here is to eliminate the need for an editor or author to
continually build a list of items used in the document and to ensure
only
items which are used are recorded in the subsequent table.

Any thoughts or suggestions would be greatly appreciated. Thank you in
advance for your assistance. Bill
 

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