A solution Please

S

Steved

Hello from Steved

..Text = "<[A-Za-z]@>"
"finds the first word on the first line"

Selection.Delete Unit:=wdCharacter, Count:=1
"deletes anything left off the first word on the first line."

With Selection.Find.Font
.Size = "30"
.Bold = True
"Finds the next first line with Font 30 and bold.

The below is my attempt, is there a better solution please. Thankyou.

Sub Text()
Dim i As Long, pararange As Range
For i = 1 To ActiveDocument.Paragraphs.Count
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<[A-Za-z]@>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Extend
Selection.HomeKey Unit:=wdLine
Selection.Delete Unit:=wdCharacter, Count:=1
With Selection.Find.Font
.Size = "30"
.Bold = True
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Selection.Find.Execute
End With
Next i
End Sub
 
J

Jezebel

You really need to ask a question, if you want someone to suggest an answer.
You can't expect people to read your code trying to work out what it's
supposed to do, and then to debug it for you.
 
S

Steved

Hello Jezebel from Steved

Thats what I thought I was doing, I only put my attempt in to show
that I had a go at it.

Okay here is the question
I would like to find on the first line "<[A-Za-z]@>"
which as you all know will find the first word, As I have
numbers on the left off the first word I want it to delete leaving
the first word, then go onto the next line when font 30 is found
and repeat, until end of document.

Font 30 is a number ie 1 up to 10 but only apears once on the first line ie 7
as an example.

Thankyou.

Jezebel said:
You really need to ask a question, if you want someone to suggest an answer.
You can't expect people to read your code trying to work out what it's
supposed to do, and then to debug it for you.




Steved said:
Hello from Steved

.Text = "<[A-Za-z]@>"
"finds the first word on the first line"

Selection.Delete Unit:=wdCharacter, Count:=1
"deletes anything left off the first word on the first line."

With Selection.Find.Font
.Size = "30"
.Bold = True
"Finds the next first line with Font 30 and bold.

The below is my attempt, is there a better solution please. Thankyou.

Sub Text()
Dim i As Long, pararange As Range
For i = 1 To ActiveDocument.Paragraphs.Count
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<[A-Za-z]@>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Extend
Selection.HomeKey Unit:=wdLine
Selection.Delete Unit:=wdCharacter, Count:=1
With Selection.Find.Font
.Size = "30"
.Bold = True
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Selection.Find.Execute
End With
Next i
End Sub
 
H

Helmut Weber

Hi Steve,

the crucial point is more the definition of the task,
than the task itself.

Seems you'd like to delete digits
with a size of 30
which are bold
which are located at the start of paragraphs.

Right?

Greetings from Bavaria, Germany

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

Steved

Hello Helmut from Steved

the crucial point is more the definition of the task,
is find the first digit that has a font that is 30 and Bold at the begining
off a line.
ok once found, now find <[A-Za-z]@>
finally delete everthing left of it so all is left is <[A-Za-z]@>

Ok now go through the document and find every instance that has a line
with the font 30 and bold digit and repeat the above.

Thankyou for taking timeout on my query.
 
J

Jezebel

You're going to have to iterate the document's paragraphs to do this, so
don't bother with the built-in Find and replace function. Try something
along these lines --

Dim pPar as Word.Paragraph
Dim pChar as Word.Range
Dim pIndex as long

For each pPar in ActiveDocument.Paragraphs

Set pChar = pPar.Range.Characters(1)
If pChar like "[0-9]" and pChar.Font.Size = 30 then
pIndex = 2
Do while pIndex <= len(pPar.Range.Length)
if pPar.Range.Characters(pIndex) like "[A-Za-z]" then
pPar.Range = mid$(pPar.Range, pIndex)
exit do
end if
Loop
end if
Next



Steved said:
Hello Helmut from Steved

the crucial point is more the definition of the task,
is find the first digit that has a font that is 30 and Bold at the
begining
off a line.
ok once found, now find <[A-Za-z]@>
finally delete everthing left of it so all is left is <[A-Za-z]@>

Ok now go through the document and find every instance that has a line
with the font 30 and bold digit and repeat the above.

Thankyou for taking timeout on my query.



Helmut Weber said:
Hi Steve,

the crucial point is more the definition of the task,
than the task itself.

Seems you'd like to delete digits
with a size of 30
which are bold
which are located at the start of paragraphs.

Right?

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
S

Steved

Hello Jezebel from Steved

1 44890 Judderbar

I've tried your macro only to find it is not working

Ok 1 off 1 44890 is the font 30 and 1 44890 to be deleted to leave the first
word in the above case Judderbar

Do while pIndex <= len(pPar.Range.Length)
the above is producing an error when I run the F8 Key

I know Jezebel it is a small issue to get your macro to work
I spent a couple off hours trying but to no go.
Would you please have a look for me.

Once again thankyou for taking time out.
Below is the macro.

Sub Testz()
Dim pPar As Word.Paragraph
Dim pChar As Word.Range
Dim pIndex As Long

For Each pPar In ActiveDocument.Paragraphs

Set pChar = pPar.Range.Characters(1)
If pChar Like "[0-9]" And pChar.Font.Size = 30 Then
pIndex = 2
Do While pIndex <= Len(pPar.Range)
If pPar.Range.Characters(pIndex) Like "[A-Za-z]" Then
pPar.Range = Mid$(pPar.Range, pIndex)
Exit Do
End If
Loop
End If
Next
End Sub



Jezebel said:
You're going to have to iterate the document's paragraphs to do this, so
don't bother with the built-in Find and replace function. Try something
along these lines --

Dim pPar as Word.Paragraph
Dim pChar as Word.Range
Dim pIndex as long

For each pPar in ActiveDocument.Paragraphs

Set pChar = pPar.Range.Characters(1)
If pChar like "[0-9]" and pChar.Font.Size = 30 then
pIndex = 2
Do while pIndex <= len(pPar.Range.Length)
if pPar.Range.Characters(pIndex) like "[A-Za-z]" then
pPar.Range = mid$(pPar.Range, pIndex)
exit do
end if
Loop
end if
Next



Steved said:
Hello Helmut from Steved

the crucial point is more the definition of the task,
is find the first digit that has a font that is 30 and Bold at the
begining
off a line.
ok once found, now find <[A-Za-z]@>
finally delete everthing left of it so all is left is <[A-Za-z]@>

Ok now go through the document and find every instance that has a line
with the font 30 and bold digit and repeat the above.

Thankyou for taking timeout on my query.



Helmut Weber said:
Hi Steve,

the crucial point is more the definition of the task,
than the task itself.

Seems you'd like to delete digits
with a size of 30
which are bold
which are located at the start of paragraphs.

Right?

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
J

Jezebel

I have no idea what this is supposed to mean:

"Ok 1 off 1 44890 is the font 30 and 1 44890 to be deleted to leave the
first
word in the above case Judderbar"

Are these special characters?


And yes, this line will throw an error: len(pPar.Range.Length)

Where did the .Length come from ?







Steved said:
Hello Jezebel from Steved

1 44890 Judderbar

I've tried your macro only to find it is not working

Ok 1 off 1 44890 is the font 30 and 1 44890 to be deleted to leave the
first
word in the above case Judderbar

Do while pIndex <= len(pPar.Range.Length)
the above is producing an error when I run the F8 Key

I know Jezebel it is a small issue to get your macro to work
I spent a couple off hours trying but to no go.
Would you please have a look for me.

Once again thankyou for taking time out.
Below is the macro.

Sub Testz()
Dim pPar As Word.Paragraph
Dim pChar As Word.Range
Dim pIndex As Long

For Each pPar In ActiveDocument.Paragraphs

Set pChar = pPar.Range.Characters(1)
If pChar Like "[0-9]" And pChar.Font.Size = 30 Then
pIndex = 2
Do While pIndex <= Len(pPar.Range)
If pPar.Range.Characters(pIndex) Like "[A-Za-z]" Then
pPar.Range = Mid$(pPar.Range, pIndex)
Exit Do
End If
Loop
End If
Next
End Sub



Jezebel said:
You're going to have to iterate the document's paragraphs to do this, so
don't bother with the built-in Find and replace function. Try something
along these lines --

Dim pPar as Word.Paragraph
Dim pChar as Word.Range
Dim pIndex as long

For each pPar in ActiveDocument.Paragraphs

Set pChar = pPar.Range.Characters(1)
If pChar like "[0-9]" and pChar.Font.Size = 30 then
pIndex = 2
Do while pIndex <= len(pPar.Range.Length)
if pPar.Range.Characters(pIndex) like "[A-Za-z]" then
pPar.Range = mid$(pPar.Range, pIndex)
exit do
end if
Loop
end if
Next



Steved said:
Hello Helmut from Steved

the crucial point is more the definition of the task,
is find the first digit that has a font that is 30 and Bold at the
begining
off a line.
ok once found, now find <[A-Za-z]@>
finally delete everthing left of it so all is left is <[A-Za-z]@>

Ok now go through the document and find every instance that has a line
with the font 30 and bold digit and repeat the above.

Thankyou for taking timeout on my query.



:

Hi Steve,

the crucial point is more the definition of the task,
than the task itself.

Seems you'd like to delete digits
with a size of 30
which are bold
which are located at the start of paragraphs.

Right?

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
H

Helmut Weber

Hi Steve,

have a look at this one, which should delete
all numeric strings of size 30 of a length of one and
all leading blanks in addition from the start of a paragraph.

There may be methods to speed it up,
if performace matters.

Sub test34556()
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Range.Paragraphs
While _
oPrg.Range.Characters.First = " " _
Or (oPrg.Range.Characters.First.Font.Size = 30 And _
IsNumeric(oPrg.Range.Characters.First))
oPrg.Range.Characters.First.Delete
Wend
Next
End Sub

And forgive me for saying so,
a bit more precision in formulating your questions,
might make it easier to help.

Greetings from Bavaria, Germany

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

Steved

Hello Jezebel from Steved

Do while pIndex <= len(pPar.Range.Length)
If you are prefering to the above,This is what you gave me in your previous
post
When I pushed F8 to run threw your script it came up with an error, I spent
sometime to my limited knowledge trying to get it to function.

Jezebel said:
I have no idea what this is supposed to mean:

"Ok 1 off 1 44890 is the font 30 and 1 44890 to be deleted to leave the
first
word in the above case Judderbar"

Are these special characters?


And yes, this line will throw an error: len(pPar.Range.Length)

Where did the .Length come from ?







Steved said:
Hello Jezebel from Steved

1 44890 Judderbar

I've tried your macro only to find it is not working

Ok 1 off 1 44890 is the font 30 and 1 44890 to be deleted to leave the
first
word in the above case Judderbar

Do while pIndex <= len(pPar.Range.Length)
the above is producing an error when I run the F8 Key

I know Jezebel it is a small issue to get your macro to work
I spent a couple off hours trying but to no go.
Would you please have a look for me.

Once again thankyou for taking time out.
Below is the macro.

Sub Testz()
Dim pPar As Word.Paragraph
Dim pChar As Word.Range
Dim pIndex As Long

For Each pPar In ActiveDocument.Paragraphs

Set pChar = pPar.Range.Characters(1)
If pChar Like "[0-9]" And pChar.Font.Size = 30 Then
pIndex = 2
Do While pIndex <= Len(pPar.Range)
If pPar.Range.Characters(pIndex) Like "[A-Za-z]" Then
pPar.Range = Mid$(pPar.Range, pIndex)
Exit Do
End If
Loop
End If
Next
End Sub



Jezebel said:
You're going to have to iterate the document's paragraphs to do this, so
don't bother with the built-in Find and replace function. Try something
along these lines --

Dim pPar as Word.Paragraph
Dim pChar as Word.Range
Dim pIndex as long

For each pPar in ActiveDocument.Paragraphs

Set pChar = pPar.Range.Characters(1)
If pChar like "[0-9]" and pChar.Font.Size = 30 then
pIndex = 2
Do while pIndex <= len(pPar.Range.Length)
if pPar.Range.Characters(pIndex) like "[A-Za-z]" then
pPar.Range = mid$(pPar.Range, pIndex)
exit do
end if
Loop
end if
Next



Hello Helmut from Steved

the crucial point is more the definition of the task,
is find the first digit that has a font that is 30 and Bold at the
begining
off a line.
ok once found, now find <[A-Za-z]@>
finally delete everthing left of it so all is left is <[A-Za-z]@>

Ok now go through the document and find every instance that has a line
with the font 30 and bold digit and repeat the above.

Thankyou for taking timeout on my query.



:

Hi Steve,

the crucial point is more the definition of the task,
than the task itself.

Seems you'd like to delete digits
with a size of 30
which are bold
which are located at the start of paragraphs.

Right?

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
S

Steved

Hello Helmut from Steved

3 960x2 Rough House

Ok your Macro will delete the 3 from above been font 30
please can you take it one more stage and that is delete to the first word,
leaving in the above case Rough House, apart from that your macro is very
quick
and I thankyou.
 
H

Helmut Weber

Hi Steve,

things get a bit clearer now. Your main problem is
a misunderstanding of Word's definition of "word".
Put your sample text

3 960x2 Rough House

into a new document and try the following in single step mode:

Dim oWrd As Object
For Each oWrd In ActiveDocument.Words
oWrd.Select
Next

You need a clear definition of what you want to do at first
in natural language! Then in pseudocode,
then in code. As you see, in your other example
1 44890 Judderbar
there was no additional x.
Delete an digit of size 30 and any space from the
beginning of a paragraph was sufficient for "1 44890 Judderbar".
But not for "3 960x2 Rough House".
Your description has to cover all (!) possible variations.
What if there was "3x 95xy x45z Judderbar"?

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

Steved

Hello Helmut from Steved

I finally understand what I was asking.

I am using your example 3x 95xy x45z Judderbar

The 3x 95xy x45z is always in small caps hence the first word starts with a
Capital Letter, So being ignorant or lack of understand code, is it not
possible in the macro you gave me to put in a code that will reconize the
first Capital Letter as in Judderbar.

Once again thanks for your patience.

Thankyou.
 
H

Helmut Weber

Hi Steve,
The 3x 95xy x45z is always in small caps
hence the first word starts with a
Capital Letter

The letters in 3x 95xy x45z are no small caps,
the are lowercase letters. Small caps look very much like caps,
only that they are a bit smaller.
Try:
3 960x2 Rough House
3 9602 Rough House
3 9x60x2v 2c Rough House

Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Range.Paragraphs
While LCase(oPrg.Range.Characters.First) = _
oPrg.Range.Characters.First
oPrg.Range.Characters.First.Delete
Wend
Next

This time disregaring font size etc.

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

Steved

Hello Helmut

Sorry Helmut I did actually means lowercase
I tried your macro And it does as I require.

I thankyou for your patience and time on this exercise for me.

Have a good day.

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

Top