【发布时间】:2023-03-07 02:17:01
【问题描述】:
我正在使用此代码,它专门将文本放置在我想要使用此代码的精确单元格中:
Dim myText1 As String
Dim myText2 As String
myText1 = "Header"
myText2 = "Body"
With ActiveDocument.Tables(1).Cell(2, 2).Range
.Font.Name = "Times New Roman"
.Font.Size = 12
.Font.Bold = True
.Font.Underline = True
.Text = myText1 & vbCr & vbCr & myText2
End With
我遇到的问题是“myText2”不应该加下划线或粗体。
我试过这个:
Dim myText1 As String
Dim myText2 As String
myText1 = "Header"
myText2 = "Body"
With ActiveDocument.Tables(1).Cell(2, 2).Range
.Font.Name = "Times New Roman"
.Font.Size = 12
.Font.Bold = True
.Font.Underline = True
.Text = myText1 & vbCr & vbCr
.Font.Bold = False
.Font.Underline = False
.Text = myText2
End With
但发生的情况是第一个 myText1 被删除,剩下的只有 myText2。
还有这个
With ActiveDocument.Tables(1).Cell(2, 2).Range
.Font.Name = "Times New Roman"
.Font.Size = 12
.Font.Bold = True
.Font.Underline = True
.InsertAfter myText1 & vbCr & vbCr
.Font.Bold = False
.Font.Underline = False
.InsertAfter myText2
虽然这会附加文本,但整个帖子的格式没有下划线或粗体,而最终结果应该看起来像
标题
身体
我怎样才能重新格式化 myText2,让它发布,而不会丢失上面格式化的 myText1?
【问题讨论】: