Text Formating

  • Thread starter Thread starter Rahul Gupta
  • Start date Start date
R

Rahul Gupta

Hello There,

I have created a Macro and i want it to return formated text to be appended
to a text.

For Eg. If my macro Return "I Love You" then i need it to be formated.

="My Response is " & <Bold><Italics>macro Name</bold></Italics> & ". Hope
you like it".

How can i do this?

Regards
 
You cannot format the text itself (that is, within the code)... what you
need to do is insert the text into a cell and then apply the formatting you
want to the characters you want. Here is a code example to give you the idea
of what I mean...

Sub Test()
Dim Answer As String
Answer = InputBox("Tell me something...")
With Range("F5")
.Value = "My Response is " & Answer & ". Hope you like it."
With .Characters(16, Len(Answer)).Font
.Bold = True
.Italic = True
End With
End With
End Sub
 
Not too clear on what you need but maybe you can adapt this?

Sub Highlight_Word()
Dim rng As Range
Dim Cell As Range
Dim start_str As Integer
On Error GoTo endit
myword = InputBox("Enter the search string ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
Set rng = Selection
With rng
.Font.FontStyle = "regular"
.Value = "My response is " & myword & ". Hope you like it"
start_str = InStr(.Value, myword)
If start_str Then
.Characters(start_str, Mylen).Font.FontStyle = "bold italic"
End If
End With
endit:
End Sub


Gord Dibben MS Excel MVP
 
Back
Top