VBA代码在excel中使标签之间的文本变粗 [英] VBA code in excel to made text between tags bold
问题描述
注意 - 给定单元格内有多个标签集合。
这应该做你想要的:
Sub BoldTags()
Dim X As Long,BoldOn As Boolean
BoldOn = False'从单元格开始的默认值不为粗体
对于X = 1 To Len ActiveCell.Text)
如果UCase(Mid(ActiveCell.Text,X,3))=&B然后
BoldOn = True
ActiveCell.Characters(X,3).Delete
End If
如果UCase(Mid(ActiveCell.Text,X,4))=< / B>中然后
BoldOn = False
ActiveCell.Characters(X,4).Delete
End If
ActiveCell.Characters(X,1).Font.Bold = BoldOn
Next
End Sub
目前设置为在活动单元上运行,您可以直接在一个循环来做一整列。您可以轻松地将此代码适用于其他HTML标签,用于单元格格式(即斜体等)
这是在我测试的单元格(减去<)后面的空格:样品& B>碲< / b> st< B>粗体< / B>结束
结果是:粗体结束 Te st
希望有助于
I have a csv file which includes the html tags < b > and <\ b > to signify bold text. (I.e several words between these tags, in a longer block of text within the cell, should be bold). Is there a way using vba code in excel to strip the tags, and make the text between the tags bold?
Note - There are sometime multiple sets of tags within a given cell.
This should do what you want:
Sub BoldTags()
Dim X As Long, BoldOn As Boolean
BoldOn = False 'Default from start of cell is not to bold
For X = 1 To Len(ActiveCell.Text)
If UCase(Mid(ActiveCell.Text, X, 3)) = "<B>" Then
BoldOn = True
ActiveCell.Characters(X, 3).Delete
End If
If UCase(Mid(ActiveCell.Text, X, 4)) = "</B>" Then
BoldOn = False
ActiveCell.Characters(X, 4).Delete
End If
ActiveCell.Characters(X, 1).Font.Bold = BoldOn
Next
End Sub
Currently set to run on the activecell, you can just plop it in a loop to do a whole column. You can easily adapt this code for other HTML tags for Cell formatting (ie italic etc)
This was in the cell I tested on (minus the space after <): Sample < b>Te< /b>st of < B>bolding< /B> end
The result was: Sample Test of bolding end
Hope that helps
这篇关于VBA代码在excel中使标签之间的文本变粗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!