Macro to Select Text between Two keywords and create a new document

N

Name

Hi ,

I am looking for a Macro which will Copy the text
between Keyword say "RESOURCE:" and "END Resource:"

The selected text should copied to New document and save
it as docname#1.doc


Note : my word doc may contain multiple "RESOURCE:"
and "END Resource:" keywords. so ..based on
this ...macro should look through whole document for the
keywords and save text in a new documents.

Hope I am clear...

thanks in advance
 
H

Helmut Weber

Hi,
could you give us an example, containing the real
keywords? Would make things a lot easier. One
complication e.g. is, that your example starts and
ends with the same word, besides capitalization.
 
G

Guest

Hi ..Thanks for responding ...

My document may have pages ranging from 10-15.
and i need to separate the text into new documents based
on the keywords "RESOURCE:" and "END-resource:"

The above keywords may be anywhere in the document. please
check the sample text ...thank you
*********************************************************

Resource : VENU

Start with an open document - any document containing some
text -


and type in a couple of the characters you intend to use
as markers. Select a character not commonly used in
writing

- for example '#' - and place some a little distance apart
in the text. Put the text cursor between the two. Now
-
- select
-
-
- Tools/Macro and enter a name, something like
CountBetweenMarkers. Choose a key sequence to activate the
-
-
- new macro - using a menu option or toolbar button would
be counter-productive. Don't forget to click on

End-Resource: VENU


Resource : XYZ

- Assign after you've selected your sequence and before
closing the Keyboard dialog. Start to record the macro
-
- using the document that you prepared:

- for example '#' - and place some a little distance
apart in the text. Put the text cursor between the two.
Now
-
- select
-
-
- Tools/Macro and enter a name, something like
CountBetweenMarkers. Choose a key sequence to activate the
-
-
- new macro - using a menu option or toolbar button would
be counter-productive. Don't forget to click on


End-Resource: XYZ
***********************************************************






*******************************************************
 
H

Helmut Weber

Hi both of you,
just one more solution,
hi Christian,
I just couldn't resist, experimenting with this for
quite some time this afternoon:
Sub Test444()
Dim i As Integer
Dim oRng As Range
Set oRng = ActiveDocument.Range
Resetsearch ' necessary? advisable?
With oRng.Find
.Text = "Resource :*End-Resource:"
.MatchWildcards = True
While .Execute
i = i + 1
oRng.MoveStart unit:=wdCharacter, Count:=10
' in order to get the spaces before the keyword, too
oRng.MoveEnd unit:=wdWord, Count:=-4
Documents.Add
With Documents(1)
.Range.InsertAfter oRng.FormattedText
.SaveAs "c:\test\test-" & Format(i, "00") & ".doc"
.Close
End With
' define the range to be searched anew
oRng.Start = oRng.End
oRng.End = ActiveDocument.Range.End
Wend
End With
Resetsearch ' advisable
End Sub
Sub Resetsearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
Greetings from Bavaria, Germany
Helmut Weber, MVP (as Christian)
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 

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