【发布时间】:2020-11-15 19:52:15
【问题描述】:
我有以下工作代码。我添加了 With 语句,但它格式化了页面上的所有文本。 此代码从 Excel 表中获取每一行,并提取列标题(问题)和其下方的单元格值(答案)。
我的目标是让问题以粗体和一种字体大小显示,而答案则低于正常字体和较小的大小。 我尝试仅将 With 语句包装在标题代码周围,但它仍然对整个页面进行样式化
For Each cell In tbl.DataBodyRange.Rows:
If cell.EntireRow.Hidden = False Then
hiddenCell = cell.Row
For Each Header In tbl.HeaderRowRange:
With WordDoc
.Styles(wdStyleHeading1).Font.Name = "Arial"
.Styles(wdStyleHeading1).Font.Size = 12
.Styles(wdStyleHeading1).Font.Bold = True
.Styles(wdStyleHeading1).Font.Color = wdColorBlack
.Range(0).Style = .Styles(wdStyleHeading1)
headerCol = wks.Cells.Find(Header).Column
WordDoc.Content.InsertAfter (vbNewLine)
WordDoc.Content.InsertAfter Range(Header.Address).Value & ": "
WordDoc.Content.InsertAfter (vbNewLine)
WordDoc.Content.InsertAfter (Cells(hiddenCell, headerCol).Value)
'WordDoc.Content.InsertAfter (vbNewLine)
End With
Next
WordDoc.Sections.Add
【问题讨论】:
标签: excel vba ms-word font-face font-size