Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ANother question here on Microsoft Words(Macro)...Its urgent... 1

Status
Not open for further replies.

JasonLiew

Programmer
Joined
Oct 15, 2001
Messages
37
Location
SG
Hi there,

Well, i've got another prob which goes like this...
I wanted to select a certain line of words, copy these selected lines, and paste em' on another word document. The problem now is: how do i select a CERTAIN LINE of WORDS and to paste em' on another document. The format of my document is something like the one below:

ABCDEF ptdltd

Section 1 : Delete

Section 2 : Delete

Approved By: someone

I wanted to select only the "Section 1 : Delete" to "Section 2 : delete".

Could anyone please enlighten mi. Its really urgent. Thanks in advance..

Adieu
Jason....
 
To start you off:

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Section 1 :*Section 2 :"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndOf wdParagraph, wdExtend
 
I'm sorry i didn't explain properly, but the "Section" is not fixed. It will sometimes have only "section 1:" and some other times till "Section 3". How do i grab all those Sections out? thanz a million justin. Pls solve my doubts...thanz....
 
Maybe this will help

Sub test()
Dim oDoc As Word.Document
Dim oPara As Paragraph
Dim oNew As Word.Document
Dim oNewPara As Paragraph

Set oDoc = ActiveDocument
Set oNew = Documents.Add
oNew.Activate
For Each oPara In oDoc.Paragraphs
If LCase$(Left$(oPara.Range.Text, 9)) Like "section #" Then
oPara.Range.Copy
Set oNewPara = oNew.Paragraphs.Add
oNewPara.Range.Paste
End If
Next oPara

Set oNewPara = Nothing
Set oPara = Nothing
Set oDoc = Nothing
Set oNew = Nothing
End Sub
 
Hi Justin,

What you mean is that i can set oDOc and oNew as the one below:

set oDoc = "C:\DCR.doc"
set oNew = "C:\Amend.doc"

Do i need to loop for the "#" sign for the "section #" you've shown above?
Thanz alot.....and sorry for the trouble i've caused for ya...

Thanz,
Jason
 
OH justin,

one more thing....The "section #" will sometimes be accompany by things like:

Section 1 : ABCDEFG

Section 2 : THIS IS THE THINGS ACCOMPANYING THE SECTION

How to do it then? Thanz again....

Adieu,
Jason
 

Replace
Set oDoc = ActiveDocument
Set oNew = Documents.Add
With
Set oDoc = Documents.Open("C:\DCR.doc")
Set oNew = Documents.Open("C:\Amend.doc")
These should be existing files however

Like "section #" will match 'section 0', 'section 4', 'section 0' so no need for a loop.
'#' matches any digit (0,1,2,...9)

The If statement just checks if the paragraph starts with the text 'Section ' followed by any digit

oPara.Range.Copy copies the 'entire paragraph' so it would include the text following 'section #' (ex. " : THIS IS THE THINGS ACCOMPANYING THE SECTION")

by 'entire paragraph' I mean everything from 'section #' to the paragraph mark, inclusive
 
Yoz Justin,

You have reaaly been a great help....thanz alot....And i dun think any words or speech could describe my gratitude to ya....thanz alot....I own u one....Care to keep in contact?? maybe thru email? mine is c0ol82@hotmail.com

note: the second word is a digit "0".....

You r a great programmer and i hope to make fren wif u...

Oh yar, I'm 19/m/Singaporean....wat bout' ya? see ya....once again...Merci Beaucoup....A bientot....

With Regards,
Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top