简体   繁体   中英

Format specific text within a cell with VBA?

When I use Excel it allows me to set specific words within a cell to bold or italic or even change the text size.

Is there a way of doing this in VBA?

I have two cells with text. One cell contains a list of words which I separated into an array. The other cell contains a few sentences.

I want to write a macro that highlights all words from cell 1 in cell 2.

My idea was to use the array and InStr to search for the position of my words in cell 2. Once found I wanted to split cell 2, format one word an put everything back together.

Maybe this is possible via Word?

I believe the answer could be found here: excel vba: make part of string bold

Specifically,

ActiveCell.FormulaR1C1 = "name/A/date" & Chr(10) & "name/B/date" & Chr(10) & "name/C/date"
With ActiveCell.Characters(Start:=25, Length:=4).Font
    .FontStyle = "Bold"
End With

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM