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:
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: