使用VBA格式化单元格中的特定文本吗? [英] Format specific text within a cell with VBA?
问题描述
当我使用Excel时,它允许我将单元格中的特定单词设置为粗体或斜体,甚至更改文本大小.
When I use Excel it allows me to set specific words within a cell to bold or italic or even change the text size.
在VBA中有做到这一点的方法吗?
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.
我想编写一个突出显示单元2中单元1中所有单词的宏.
I want to write a macro that highlights all words from cell 1 in cell 2.
我的想法是使用数组和InStr搜索单词在单元格2中的位置.找到后,我想拆分单元格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.
也许可以通过Word做到这一点?
Maybe this is possible via Word?
推荐答案
我相信可以在这里找到答案: excel vba:将字符串的一部分加粗
I believe the answer could be found here: excel vba: make part of string bold
具体地说,
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
这篇关于使用VBA格式化单元格中的特定文本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!