Just the first Line please

S

Steved

Hello from Steved
I want to use the bottom vba please

Sub Word2()
Dim pPar As Word.Paragraph
Dim s As String
Dim p As Long

For Each pPar In ActiveDocument.Paragraphs

s = pPar.Range.Text
p = InStr(1, s, " ")
If p > 0 Then
p = InStr(p + 1, s, " ")
If p > 0 Then
pPar.Range.Text = Mid$(s, p + 1)
End If
End If

Next
End Sub

to Delete left Of Oscar's View and the right of it
as in the example below please ("only the first line and
leave the rest and then find the next" ) Thankyou.

Oscar's View

1. x9003 Oscar's View (3) 4g br
Oregon (USA)-Interview (by Wiganthorpe)
- (56)
Stats:
Trnr: Kenny Rae (Ruakaka/Cambridge)
Ownr: A L Richards
All 10:0:0:3:1
Prz $1,850
F 4:0:1
E 1:0:0
S 2:0:1
H 3:0:1
C 0:0:0
D 3:0:1 F90 2:0:0:0
F30 1:0:0:1
2Up 2:0:0:1 Fav 1:0:0:0
2 Fav 1:0:0:0
Win $0.00
Plc $2.12
Perf: CBRY 14 Aug 2004 7 dys 15 of 18 P-MdnSpec $27K 1800
E3.5 Bruce Herd 56 (9) 4/5 $9.90 1st: King Luskin 1:53.70
16.3L
AVON 25 Aug 2004 11 dys 10 of 11 MdnHwt $5K 1600 H5.2
Richard Eynon 63.5->60.5 (1) 2/2 $4.85 1st: Dollarahead
1:46.13 8.7L
WHAN 05 Jan 2005 - 9 of 14 Mdn $5K 1200 F2.4 Tony Allan
56 (4) 8/8 $17.55 1st: Universal Charm (AUS) 1:10.49 8.5L
HBAY 20 Jan 2005 15 dys 10 of 11 Mdn $5K 1400 F2.2 Hayden
Tinsley 56 (7) 7/7 $18.50 1st: Rhythm Dancer 1:24.45 7.3L
WELL 29 Jan 2005 9 dys 13 of 18 P-Mdn $14K 1400 F2.0 Sara-
Lee Kelly 56->54 (10) 18/18 $114.40 1st: Rokocoko 1:24.29
12.2L
HBAY 03 Mar 2005 33 dys 3 of 10 Mdn $5K 1200 F2.3 Chris
Carmine 56->54 (4) 10/10 $42.40 1st: Happy Harry 1:10.82
1.9L
-
 
H

Helmut Weber

Hi Steve,

what exactly are you searching for,
always "Oscar's View" in the first
line of a multiline paragraph??
Or the part of the first line in a multiline
paragraph that comes between the second space
and the forth space?

Is there an end-of-line character?

You may use character(182) ¶ to indicate
end of paragraph in a posting, and
let's say, character(172) ¬ or some other
odd character to indicate a line break.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
S

Steved

Hello Helmut.

Each accurrence is first line in a multi Paragraph
The first line will always be as set out below
1. x9003 Oscar's View (3) 4g br
2. 16P42 Sensational (4) 7g br
3. 23x11 Mako Polo (1) 5g br.

The first line always starts with a numeral followed by a
full stop as shown above.

In the above case the objective off the macro is to find
the numeral 1. then find in this case Oscar's View once
found delete 1. x9003 and (3)4g br leaving Oscar's View,
now the macro must find the next one to do numeral 2. in
this case, find the word in the first line of a multi
paragraph which happens to be Sensational, then delete 2.
16P42 and (4) 7g br leaving the word Sensational and now
the macro will move onto the next in this case find the
numeral 3 and the full stop ie 3.

Each time the macro is only dealing with the first line of
the multi paragraph and ignoring the rest.

If I can achieve this I will be happpy.

Thankyou.
 
H

Helmut Weber

Hi Steve,

like this:

Sub Test6789()
' select paragraph
' get first line
' remove last character (linefeed)
' find second space in first list
' delete until including second space
' find next opening parenthesis
' delete til end including space before parenthesis
' add linefeed again

Dim oPrg As Paragraph
Dim sTmp As String
Dim lPos As Long

For Each oPrg In ActiveDocument.Range.Paragraphs
oPrg.Range.Select
Selection.Collapse
Selection.Bookmarks("\line").Select
sTmp = Selection.Bookmarks("\line").Range.Text
sTmp = Left(sTmp, Len(sTmp) - 1)
MsgBox "[" & sTmp & "]"
lPos = InStr(1, sTmp, " ")
lPos = InStr(lPos + 1, sTmp, " ")
sTmp = Right(sTmp, Len(sTmp) - lPos)
lPos = InStr(sTmp, "(")
sTmp = Left(sTmp, lPos - 2)
MsgBox "[" & sTmp & "]"
Selection.Bookmarks("\line").Range.Text = sTmp & Chr(11)
Next
End Sub

which is not the shortest possible solution, probably,
but I thought, I'd better show all steps in detail.

Beware of empty paragraphs!
MsgBox "[" & sTmp & "]" is for checking progress.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
S

Steved

Hello Helmut from Steved

Firstly when I run your macro it is giving me the result
I want and I thankyou, However I am getting a error, On
the line I've highlighted, would you kindly tell me how I
can fix this issue. Once again Thankyou.

Run-time error '5'

invalid procedure call or argument

sTmp = Left(sTmp, lPos - 2)

Sub Test6789()

Dim oPrg As Paragraph
Dim sTmp As String
Dim lPos As Long

For Each oPrg In ActiveDocument.Range.Paragraphs
oPrg.Range.Select
Selection.Collapse
Selection.Bookmarks("\line").Select
sTmp = Selection.Bookmarks("\line").Range.Text
sTmp = Left(sTmp, Len(sTmp) - 1)
lPos = InStr(1, sTmp, " ")
lPos = InStr(lPos + 1, sTmp, " ")
sTmp = Right(sTmp, Len(sTmp) - lPos)
lPos = InStr(sTmp, "(")
sTmp = Left(sTmp, lPos - 2)
Selection.Bookmarks("\line").Range.Text = sTmp & Chr
(11)
Next
End Sub
 
H

Helmut Weber

Hi Steve,

the macro is a demo to be run once,
and works, if all paragraphs have
a first line, as it was specified.

If you want to too add new paragraphs
of the same structure and run the macro
again, then you have to set up some check,
whether a paragraph shall be processed.

Making this bulletproof is more difficult
then the whole macro itself, if possible at all.

You might check,
whether the first line starts with a number
of type long followed by a period (full stop),
followed by a space,
in addition
whether it contains 1 opening and 1 closing
parenthesis and a number of type long in between
in addition
whether the closing parenthesis is followed by
a space followed by a number of type long followed
by "g" etc...

In fact you would have to set up, what linguists
call a grammer, for the first line of a paragraph,
and do a syntax check.

I'd rather suggest, you try to modify the macro
to work on selected paragraphs only.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
S

Steved

Thanks Helmut

Are you saying if I read you correctly, your macro
can be adapted if each line starts with a number followed
by a period, as an example 1., 2., 3., to 24.

Is Identifying 1. or say a 2 digit number 12 followed by
a period enough for your macro to function.

Thankyou.
 
H

Helmut Weber

Hi Steve,

could be done.

The macro can be twisted, so that it runs only if
the first line in a paragraph starts with a number
between 1 and 24 followed by a period.
But that's not the point. The point is to exclude
that, after running the macro once, no first line
remains that fullfills the criteria also.
Theory, of course. But ...
I remember database admins, who where at a complete lost,
because they used to seperate fields by inclosing them in
quotation marks. Works alright, as long as the number of
quotation marks is even. But then, it occured, that a text
contained an inch sign ", like "a 1/4" tube", and all their
database transactions resulted in chaos.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
S

Steved

Thankyou.

I will use your macro but I will tell the macro to look
for the first numeric and period once again
thankyou.
 

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

Similar Threads


Top