Adding break Lines

S

Sahana

Hi

i m trying to write a code which adds <br> when a new line is added or
when ENTER is pressed.

I have a sample code when enables me to add <b> when a word is
boldfaced. Help in anyform is appreciated.


the code that adds <b> when a word is bold faced.

Selection.HomeKey wdStory
Selection.FInd.ClearFormatting
With Selection.FInd.Font
.bold = True
End With
With Selection.FInd
Do While .Execute(FindText:="", Forward:=True,
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
With Selection
If Left(.Paragraphs(1).Style, 4) <> "Head" Then
.Font.bold = False
.InsertBefore "<b>"
.InsertAfter "</b>"
End If
.Collapse wdCollapseEnd
End With
Loop
End With
End Sub
 
P

Pesach Shelnitz

Hi,

The following macro does what I think you are asking for.

Sub AddBr()
Dim vFindText As Variant
Dim i As Long
Dim myRange As Range

vFindText = Array("^p", "^l")
Set myRange = ActiveDocument.Range
For i = 0 To UBound(vFindText)
With myRange
.start = 0
Do While .Find.Execute(findText:=vFindText(i), _
Wrap:=wdFindStop, Forward:=True) And _
.End < ActiveDocument.Range.End
.InsertBefore "<br/>"
.Collapse Direction:=wdCollapseEnd
Loop
End With
Next
Set myRange = Nothing
End Sub

However, in my opinion, the correct thing to do is to surround each
paragraph by <p> and </p> tags and to use <br/> only for line breaks.
 

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