PDA

View Full Version : Solved: How to do it? Help.......



Rakesh
05-15-2010, 02:00 PM
Hi Rocks,

I had a coding which find something and insert a text at starting of the para

Coding 1.
Sub Insert Tip1()

Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1, _
Extend:=wdExtend

Dim strSelText As String
strSelText = Selection.Text

If IsNumeric(strSelText) = True Then
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:="Tip1:"
Else

Selection.MoveDown Unit:=wdLine, Count:=1

End If
End Sub

If the first character of the para is Numeric its Insert “Tip1:” at the starting of the para.

Coding 2.
Sub Insert Tip2()
With ActiveDocument.Content.Find
.ClearFormatting
Do While .Execute(FindText:="%" & Chr(13), Forward:=True, _
Format:=True) = True
With .Parent
.StartOf Unit:=wdParagraph, Extend:=wdMove
.InsertAfter "Tip2:"
.Move Unit:=wdParagraph, Count:=1
End With
Loop
End With
End Sub

It searches for “%” & return and Insert Tip2: at the starting of the para.


Both the coding works fine. But it works separately.

Can it possible to do it Jointly i.e., if both the condition matches the Insert to be done.

Sample text for your ref
(Text to be insert on the 4th and 5th line (which always appears next to next), 7th line should remains the same.)

Archer-Daniels-Midland Co.
Philip Morris International Inc.
Reynolds American Inc.
11,886,882
AGRICULTURE<\!#209>0.35%
DaimlerChrysler North America Holding Corp.
Bank of America Corp. 1.52%
Bank of America Corp. Series L (FDIC Guaranteed)

Thanks,
Rakesh:banghead:

TonyJollans
05-16-2010, 10:44 AM
I think this will do what you want:

ActiveDocument.Content.Find.Execute _
FindText:="([0-9,]@^13)", _
MatchWildcards:=True, _
ReplaceWith:="Tip 1: \1", _
Replace:=wdReplaceAll
ActiveDocument.Content.Find.Execute _
FindText:="([!^13]@%^13)", _
MatchWildcards:=True, _
ReplaceWith:="Tip 2: \1", _
Replace:=wdReplaceAll

Rakesh
05-16-2010, 11:55 AM
Hi TonyJollans,

ThanX for your kind reply and try.

I tried the code, but it doesn't work.

Thanks,
Rakesh:banghead:

TonyJollans
05-16-2010, 03:34 PM
What did it do?

Rakesh
05-19-2010, 11:07 AM
Hi TonyJollans,

Its also inserts ("Tip 1:") when it finds the numbers at the end of the para. Below is the output for your ref:

Archer-Daniels-Midland Co.
Philip Morris International Inc.
Reynolds American Inc. Tip1: 15,236,256
Tip 1: 11,886,882
Tip 2: AGRICULTURE<\!#209>0.35%
DaimlerChrysler North America Holding Corp.
Tip 2: Bank of America Corp. 1.52%
Bank of America Corp. Series L (FDIC Guaranteed)

With a slight modification I have fix it.

ActiveDocument.Content.Find.Execute _
FindText:="(^13)([0-9,]@^13)", _
MatchWildcards:=True, _
ReplaceWith:="\1Tip 1: \2", _
Replace:=wdReplaceAll


The Coding replaces globally. But what I likes is,
Condition 1: Para Starts with the Numeric and
Condition 2: Para ends with % (Next Para to the condition 1)

If both the condition matches the text to be insert.

The text to be inserted on 4th and 5th line.
7th line and 9th line should remains the same.

The output should be as follows

Archer-Daniels-Midland Co.
Philip Morris International Inc.
Reynolds American Inc. 15,236,256
Tip 1: 11,886,882
Tip 2: AGRICULTURE<\!#209>0.35%
DaimlerChrysler North America Holding Corp.
Bank of America Corp. 1.52%
Bank of America Corp. Series L (FDIC Guaranteed)
10,253,678
Philip Morris International Inc.


Thanks,
Rakesh:banghead:

TonyJollans
05-19-2010, 12:00 PM
Combined, like this?

ActiveDocument.Content.Find.Execute _
FindText:="(^13)([0-9,]@^13)([!^13]@%^13)", _
MatchWildcards:=True, _
ReplaceWith:="\1Tip 1: \2Tip 2: \3", _
Replace:=wdReplaceAll

Rakesh
05-19-2010, 12:47 PM
Hi TonyJollans,

Its works Fine. You have saved my manual work and time.
Rocks are always Rocks.


ThanX,
Rakesh

Rakesh
05-22-2010, 07:35 AM
Hi Tony,

The Code works in Microsoft Word 2003 for Windows, But it not works in Microsoft Word 2004 for Mac "Version 11.3.5"


Can any Technicians Solve it.

Thanks,
Rakesh:banghead: