D
Designingsally
I have posted previous wanted to know how to set line break I have finally
managed to write a code which serves my purpose. But i m unable to resolve 2
issue. I hope some help comes along.
1. If the Note is already as
Note
Hello
Macro is checking that again and giving line break. I don’t want that to
happen
Eg 2
Note
hi
2. Notice the word after Note, which is “h,†I want that in Upper case
always. I m trying oRng.Words.First.Characters.First.Case = wdUpperCase
but I still end up getting that in small letter. If its in small caps it can
ignore, which the macros does.
Equivalent code and what happens
If a sentence goes like this Note i m having fun. The macro changes as
Note
i m having fun
Code
Sub FindAndReplace()
'
' FindAndReplace Macro
Dim oRng As Range
Set oRng = ActiveDocument.Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
Selection.FInd.ClearFormatting
Selection.FInd.Replacement.ClearFormatting
With Selection.FInd
.Text = "Note"
.Replacement.Text = "Note ^l"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
If oRng.Words.Last.Characters.First.Case <> wdUpperCase Then
oRng.Font.bold = False
oRng.Words.First.bold = True
oRng.Words.First.Characters.First.Case = wdUpperCase
End If
End With
Selection.FInd.Execute Replace:=wdReplaceAll
oRng.Words.Last.Characters.First.Case = wdUpperCase
' Go To Top
Selection.HomeKey Unit:=wdStory
End Sub
managed to write a code which serves my purpose. But i m unable to resolve 2
issue. I hope some help comes along.
1. If the Note is already as
Note
Hello
Macro is checking that again and giving line break. I don’t want that to
happen
Eg 2
Note
hi
2. Notice the word after Note, which is “h,†I want that in Upper case
always. I m trying oRng.Words.First.Characters.First.Case = wdUpperCase
but I still end up getting that in small letter. If its in small caps it can
ignore, which the macros does.
Equivalent code and what happens
If a sentence goes like this Note i m having fun. The macro changes as
Note
i m having fun
Code
Sub FindAndReplace()
'
' FindAndReplace Macro
Dim oRng As Range
Set oRng = ActiveDocument.Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
Selection.FInd.ClearFormatting
Selection.FInd.Replacement.ClearFormatting
With Selection.FInd
.Text = "Note"
.Replacement.Text = "Note ^l"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
If oRng.Words.Last.Characters.First.Case <> wdUpperCase Then
oRng.Font.bold = False
oRng.Words.First.bold = True
oRng.Words.First.Characters.First.Case = wdUpperCase
End If
End With
Selection.FInd.Execute Replace:=wdReplaceAll
oRng.Words.Last.Characters.First.Case = wdUpperCase
' Go To Top
Selection.HomeKey Unit:=wdStory
End Sub