【发布时间】:2016-04-21 22:59:54
【问题描述】:
我通过 VBA 从 Excel 将数据输入 Word 文档。我想像这样格式化 下列的。
1. Service Ticket# 452345: Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed do eiusmod tempor incididunt ut Labore et dolore magna aliqua。
Service Ticket 部分以粗体和斜体显示,并且描述仅以斜体显示。服务票号和说明来自 Excel 中的不同单元格。
这是我的代码:
'' Bookmark where I will be inserting the data.
wdApp.Selection.GoTo what:=-1, Name:="Service_Ticket_Comments"
Dim i As Integer
Dim serviceTicket As String
For i = 4 To shAuditTrail.Range("A4").End(xlDown).Row
'' Pulling comments from the comments column.
If Not IsEmpty(Cells(i, 11)) Then
serviceTicket = "Service Ticket #" & Cells(i, 1)
wdApp.Selection.TypeText "Service Ticket #" & Cells(i, 1)
wdApp.Selection.Font.Bold = True
wdApp.Selection.Font.Italic = True
wdApp.Selection.TypeText " - " & Cells(i, 11) & Chr(10) & Chr(10)
wdApp.Selection.Font.Italic = True
End If
Next
这会使服务单部分和描述加粗和斜体,因为选择应用于整个部分。我如何只保持第一部分粗体和斜体,而另一部分只是粗体?
【问题讨论】: