我有一个保存文本文件的程序,我想要做的是在excel中打开之前为这个文本添加一些基本样式。
我的文件通常如下所示:
Title of text
lorem ipsum dolor sit amet
我是否可以在此文本文件中编写任何可以使 文本标题'在excel中打开时粗体?
像html标记一样
<b>Title of text</b>
lorem ipsum dolor sit amet
excel有什么类似的东西吗?
答案 0 :(得分:1)
您可以使用以下代码。此代码将格式化范围A1:A13
中的文本。您可以根据需要选择要格式化的范围。只需将此代码复制到Visual Basic编辑器,然后使用“运行子”按钮运行子代码。
Sub Macro1()
Dim str As String
Dim nBold As Long
Dim nEndBold As Long
Dim nChars As Long
Set Rng = Range("A1:A13")
For Each cell In Rng
str = cell.Text
nBold = InStr(str, "<b>")
If nBold > 0 Then
nEndBold = InStr(str, "</b>")
If nEndBold = 0 Then nEndBold = 32767
nChars = nEndBold - nBold - 3
str = Replace(Replace(str, "<b>", ""), "</b>", "")
cell.Value = str
cell.Characters(nBold, nChars).Font.Bold = True
End If
Next cell
End Sub
请查看this link以获取更多信息。