Need a macro to help in Word

brianpunx

New Member
Joined
Jun 24, 2004
Messages
20
I'm hoping someone can help me with creating a macro to help me do something in Word 2003. I have many *.rtf files that need to be altered. I would like a macro that can search for a specific phrase and delete everything before that phrase in the document. Also, if possible save the altered file as *.doc rather than *.rtf.

I know this is an excel board, but everyone here was so helpful in the past in creating macros for me to use in excel I thought I'd ask on here.

Here is an example what needs to be done for each and every *.rtf file I have:
Code:
Explore by Substance Identifier started at: Fri Nov 26, 2004 at 4:51 PM 

Explored by Substance Identifier in REGISTRY. 
 
 
    REGISTRY Answers 
        0 for 2,6-diamino-5-hydroxyhexanoic acid 
        21 for -5-hydroxyhexanoic acid 
 

 
 
Get References started 

127 references were found for 16 of 21 substances in CAPLUS and MEDLINE; for each sequence, retrieve additional related references 
 

Research Topic Refine started 

31 references were found when refined using the phrase "HUMAN" 
 

Research Topic Refine started 

31 references were found when refined using the phrase "URINE OR PLASMA" 
 

Research Topic Refine started 

17 references were found when refined using the phrase "HEALTHY OR DISORDER" 
 

Copyrights: 
 
CAPLUS: Copyright 2004 ACS (The UK patent material in this product/service is UK Crown copyright and is made available with permission. (C) Crown Copyright.  The French (FR) patent material in this product/service is made available from Institut National de la Propriete Industrielle (INPI).)  
MEDLINE: Produced by the U.S. National Library of Medicine 
REGISTRY: Copyright 2004 ACS (Some records contain information from GenBank(R). See also: Benson D.A., Karsch-Mizrachi I., Lipman D.J., Ostell J., Rapp B.A., Wheeler D.L. Genbank. Nucl. Acids Res. 28(1):15-18 (2000). Property values tagged with IC are from the ZIC/VINITI data file provided by InfoChem.) 
CASREACT: Copyright 2004 ACS (In addition to reactions indexed by CAS, CASREACT contains reactions derived from the following sources:  ZIC/VINITI database (1974-1991) provided by InfoChem, INPI data prior to 1986, and Biotransformations database compiled under the direction of Professor Dr. Klaus Kieslich.) 
CHEMLIST, CHEMCATS: Copyright 2004  ACS 

 
 
 
 


Registry Number: 	83972-61-6

Absolute stereochemistry.
 


Formula: 	C6 H12 O3

CA Index Name: 	Hexanoic acid, 5-hydroxy-, (5R)- (9CI)

Other Names: 	Hexanoic acid, 5-hydroxy-, (R)-; (5R)-5-Hydroxyhexanoic acid

I would want the macro to search and find "Registry Number: " and delete everything before that in the document. So, in the example above the new document would read:
Code:
Registry Number: 	83972-61-6

Absolute stereochemistry.
 


Formula: 	C6 H12 O3

CA Index Name: 	Hexanoic acid, 5-hydroxy-, (5R)- (9CI)

Other Names: 	Hexanoic acid, 5-hydroxy-, (R)-; (5R)-5-Hydroxyhexanoic acid
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,

The code would be something like this

Code:
Documents.Open "c:\test.rtf"
   
With Selection.Find
   .ClearFormatting
   .Text = "Registry Number:"
   .Forward = True
   .Wrap = wdFindContinue
   .Execute
End With
   
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1

temp = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 4)
ActiveDocument.SaveAs FileName:=temp, fileformat:=wddocformat

The first line of this code opens a document on the c drive called test.rtf. The last line saves the modified file in the same place as an rtf.
 
Upvote 0
That code works beautifully, but how could I change it so that after it's done it's thing it closes the new .doc file?

Thanks
 
Upvote 0

Forum statistics

Threads
1,222,246
Messages
6,164,805
Members
451,917
Latest member
WEB78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top