[mso] Re: Macro help for MS Word...

  • From: "Tillotson, Robert N (US SSA)" <robert.tillotson@xxxxxxxxxxxxxx>
  • To: <mso@xxxxxxxxxxxxx>
  • Date: Wed, 14 Nov 2007 14:38:10 -0500

Shawn,

You can try this macro.  Comments should explain what's going on.
Putting the copied text at the end is a little easier in the pasting
operation whereas putting it at the front is a little easier in knowing
when you are done with the document.  I just preferred this.  You can
manall copy the index generated back to the front of the document.

Option Explicit

Sub MakeIndex()
'
'
' Macro created 11/14/2007 by robert.tillotson
'
Dim firststring As String
'set up find with wild cards to get title and word "AUTHOR"
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text =3D "(TITLE:*)(AUTHOR)"
        .Replacement.Text =3D ""
        .Forward =3D True
        .Wrap =3D wdFindContinue
        .Format =3D False
        .MatchCase =3D False
        .MatchWholeWord =3D False
        .MatchAllWordForms =3D False
        .MatchSoundsLike =3D False
        .MatchWildcards =3D True
    End With
    Selection.Find.Execute
'    Make sure we found something and then set a variable to test
'    for the end of file - which is when the next find finds the copied
first find.
    If Selection.Find.Found Then firststring =3D Selection.Text
While Selection.Find.Found
'Copy the found text
    Selection.Copy
    Selection.EndKey Unit:=3DwdLine
'Set a bookmark to come back here for next find
    With ActiveDocument.Bookmarks
        .Add Range:=3DSelection.Range, Name:=3D"placeholder"
        .DefaultSorting =3D wdSortByName
        .ShowHidden =3D False
    End With
'Go to end of document
    Selection.EndKey Unit:=3DwdStory
'Insert hard return to set off entry
    Selection.TypeParagraph
'Paste found text
    Selection.Paste
'Delete the work Author leaving the paragraph mark
    Selection.HomeKey
    Selection.EndKey Unit:=3DwdLine, Extend:=3DwdExtend
    Selection.MoveLeft Unit:=3DwdCharacter, Count:=3D1, =
Extend:=3DwdExtend
    Selection.Delete
'Go back to the bookmark
    Selection.GoTo What:=3DwdGoToBookmark, Name:=3D"placeholder"
'delete old bookmark
    ActiveDocument.Bookmarks("placeholder").Delete
'Find again
    Selection.Find.Execute
'If found first string again then done
    If Selection.Text =3D firststring Then
    Exit Sub
    End If
'Continue as before if new found text
Wend
End Sub=20


Robert Tillotson
BAE-IT
Groton Field Office
860-441-2207

-----Original Message-----
From: mso-bounce@xxxxxxxxxxxxx [mailto:mso-bounce@xxxxxxxxxxxxx] On
Behalf Of Shawn McGinniss
Sent: Wednesday, November 14, 2007 12:51 PM
To: mso@xxxxxxxxxxxxx
Subject: [mso] Macro help for MS Word...

Is there a way to record a macro that will highlight a range of text,
copy the range, and paste it onto the top of the first page?
I get "email alerts" containing new article abstracts from relevant
public health research, sometimes over a hundred pages long, but there's
never a table of contents.  So I've been going through all of them,
copying the titles of the articles, and pasting them to the top to allow
senior faculty members at Hunter College a more user-friendly way to
glean this information.

Here's an example of the format:

TITLE:          Model-based estimates of HIV acquisition due to prison
>                rape (Article, English)
> AUTHOR:         Pinkerton, SD; Galletly, CL; Seal, DW
> SOURCE:         PRISON JOURNAL 87 (3). SEP 2007. p.295-310 SAGE
>                PUBLICATIONS INC, THOUSAND OAKS
>
> ABSTRACT:       Nearly 1.4 million men are incarcerated in federal and
> state prisons in the United States. These men are disproportionately=20
> affected by HIV in comparison with the at-large male population. The=20
> elevated prevalence of HIV infection in U.S. prisons has raised=20
> concerns over the potential for intraprison HIV transmission due to=20
> rape and other forms of sexual victimization. However, the number of=20
> men who acquire HIV after being raped in U.S. prisons is not known. We

> developed a mathematical model of HIV transmission to estimate the=20
> likelihood that an incarcerated man would become infected as a result=20
> of prison rape and to provide preliminary estimates of the number of=20
> prison rape victims who acquire HIV. Our results suggest that between=20
> 43 and 93 currently incarcerated men already have or will acquire HIV=20
> as a result of being raped in prison.
>
>
------------------------------------------------------------------------
--
> TITLE:          Bronchial responsiveness to methacholine and adenosine
5
>                '-monophosphate in young children with asthma: their=20
> relationship with
>                blood eosinophils and serum eosinophil cationic protein

> (Article, English)
> AUTHOR:         Choi, SH; Kim, DK; Yu, J; Yoo, Y; Koh, YY
> SOURCE:         ALLERGY 62 (10). OCT 2007. p.1119-1124 BLACKWELL
>                PUBLISHING, OXFORD
>
> ABSTRACT:       Bronchial hyperresponsiveness is a characteristic
feature
> of asthma, and is usually measured by bronchial challenges using=20
> direct or indirect stimuli. Blood eosinophil numbers and serum levels=20
> of eosinophil cationic protein (ECP) are considered as indirect=20
> measures of airway inflammation in asthma. The aim of this study was=20
> to investigate whether bronchial responsiveness to adenosine=20
> 5'-monophosphate (AMP) is more closely associated with blood=20
> eosinophil markers, compared with that to methacholine, in young
children with asthma.
>
> Our results suggest that bronchial responsiveness to AMP is more=20
> closely related to airway inflammation, compared with that to=20
> methacholine, and support the potential usefulness of AMP challenges=20
> in detecting inflammatory changes in young children with asthma.
>
>
------------------------------------------------------------------------
--
> TITLE:          The polymorphisms of Eotaxin 1 and CCR3 genes
influence
>                on serum IgE, Eotaxin levels and mild asthmatic=20
> children in Taiwan
>                (Article, English)
> AUTHOR:         Wang, TN; Chiang, W; Tseng, HI; Chu, YT; Chen, WY;
Shih,
>                NH; Ko, YC
> SOURCE:         ALLERGY 62 (10). OCT 2007. p.1125-1130 BLACKWELL
>                PUBLISHING, OXFORD
>
> ABSTRACT:       Asthma is a complex disorder, which is known to be
> affected by interactions between genetic and environmental factors.=20
> The human Eotaxin 1 and CCR3 attract eosinophils and Th2-lymphocytes=20
> to migrate to the inflammatory foci that could represent a key=20
> mechanism in allergy and asthma.
>
> This study finding provide a strong evidence that Eotaxin 1 Thr23Thr=20
> homozygote has a protective effect on asthma and significantly=20
> decreases plasma Eotaxin 1 concentrations in asthmatics in Taiwan.
>


The highlighted titles are all I wish to extract, often from very long
documents (100+ pages).

So in theory, I'd like to record a type of "find and copy/paste" macro,
where it searches for any text between "TITLE:" and stops one character
before the A in "AUTHOR," copies that text, and appends it somewhere
else (either the top/bottom of the word doc, a new word doc, or some
other textfile).

This would save me *lots* of time, which is what PCs are supposed to do.
If only I had the knowledge...I'm familiar with recording actions in
Photoshop, but more advanced script gets very confusing.  Is this
possible?  Any help or advice would be greatly appreciated.


Thanks,

--
Shawn McGinniss
Research Assistant,
Center for Community and Urban Health
Hunter College
425 East 25 Street, W808
New York, NY 10010
Tele: (212) 481-4284
Fax: (212) 481-5015


*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx
or MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, visit the group's homepage and use the
dropdown menu at the top.  This will allow you to unsubscribe your email
address or change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso

To be able to share files with the group, you must join our Yahoo sister
group.  This group will not allow for posting of emails, but will allow
you to join and share problem files, templates, etc.:
http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for
FILE SHARING ONLY.

If you are using Outlook and you see a lot of unnecessary code in your
email messages, read these instructions that explain why and how to fix
it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************
*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, visit the group's homepage and use the dropdown 
menu at the top.  This will allow you to unsubscribe your email address or 
change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso

To be able to share files with the group, you must join our Yahoo sister group. 
 This group will not allow for posting of emails, but will allow you to join 
and share problem files, templates, etc.:  
http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE 
SHARING ONLY.

If you are using Outlook and you see a lot of unnecessary code in your email 
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************

Other related posts: