
How to maintain Bold font and underline in Text replacement
Hi There,
I am using below code to insert text into document from a
word form which has 2 command buttons "Insert"
and "cancel". However, whenever I clcik "Insert" after I
typed in bold font with underline, actual insertions are
changed as "Headings1" or"headings2" styles and positioned
in the centre without underline.
Is there anyway that I can sure the same fonts and style
that I typed are exactly showing on the document after I
click "insert"??
Many thanks
*********
Private Sub cmdInsert_Click()
ActiveWindow.ActivePane.View.ShowAll = True
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Insert text after this line:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
If Selection.Find.Execute = True Then
Selection.MoveRight
Selection.Extend "$"
Selection.Copy
End If
Application.Documents(2).Activate
ActiveDocument.ActiveWindow.View.ShowAll = True
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst
With Application.Selection.Find
.Text = "[example]"
.Forward = True
.Wrap = wdFindStop
.Replacement.Text = ""
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
While Selection.Find.Execute
.Find.Execute replace:=wdReplaceOne
Selection.Paste
Wend
End With
ActiveDocument.ActiveWindow.View.ShowAll = False
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst
Me.Close wdDoNotSaveChanges
Unload Me
End Sub