I need to insert text into a cell, via macro, and bold part of the text. How would I do that?
Example: "Regular text and bolded text"
I need to insert text into a cell, via macro, and bold part of the text. How would I do that?
Example: "Regular text and bolded text"
[vba]
With Range("A1")
.Value = "Regular text and bolded text"
.Characters(19, 11).Font.Bold = True
End With
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
But what if some of the text is always the same and some (the part I want bolded) is always different? How do I bold it then?
Cheryl
How would you, we or VBA determine what's to be bold and what's not?
Originally, the macro was in a Word template. In the Word table cell, the macro inserted the static part of the variable text, toggled bold on, then inserted the rest of the varible text. I've never really worked with Excel macros before, so I have no idea how to do the same thing in an Excel macro.
[vba]
With Range("A1")
.Value = "Regular text and bolded text"
.Characters(len_of_always_the_same_bit + 1, Len(.Value) - len_of_always_the_same_bit).Font.Bold = True
End With
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Ok, Here's the code you gave me for adding text to column B of the active row. How do I modify it to apply bold to "bolded text"? Since this doesn't use a range, I'm not sure how to alter it.
[VBA]ActiveSheet.Cells(ActiveCell.Row, "B").Value = "Regular text and bolded text"
[/VBA]
It does use a range, Cells is a range property, so it works the ame way
[vba]
Dim mpStart As Long
With ActiveSheet.Cells(ActiveCell.Row, "B")
.Value = "Regular text and bolded text"
mpStart = InStr(.Value, "bolded text")
If mpStart > 0 Then
.Characters(mpStart, Len(.Value) - mpStart).Font.Bold = True
End If
End With
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
The only thing the above code didn't do was bold the last letter in "bolded text".
It is pretty simple to work out the fix
[vba]
With ActiveSheet.Cells(ActiveCell.Row, "B")
.Value = "Regular text and bolded text"
mpStart = InStr(.Value, "bolded text")
If mpStart > 0 Then
.Characters(mpStart, Len(.Value) - mpStart + 1).Font.Bold = True
End If
End With
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber