当前,现在当我使用vba从excel复制并粘贴到单词时,一切都完美无缺,包括格式化。但是,我有一个问题,就是在粘贴到单词上后标题(在表的第一个单元格中)是黑色的。标题包含两个字母(第一个字母为黑色,第二个字母为红色),第二个字母需要红色,以反映该单词。请提供帮助和建议!
我尝试过使用pastespecial代码,但确实出现了颜色,但是格式变得混乱,如果可能的话,我希望保留使用pasteexceltable代码。谢谢!
Sub contractDCN()
Sheets("Print").UsedRange.Clear
Sheets("DCN Inputs").Select
If Not IsEmpty(Sheets("DCN Inputs").Range("ProductToggle")) Then
Sheets("DCN Master").Rows("1:26").Copy Destination:=Sheets("Print").Range("A" & Cells(Rows.Count, 1).End(xlUp).Row)
End If
If Sheets("DCN Inputs").Range("CouponOption").Value = "Fixed" Then
Sheets("DCN Master").Rows("27:34").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
ElseIf Sheets("DCN Inputs").Range("CouponOption").Value = "Floating" Then
Sheets("DCN Master").Rows("27:34").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
End If
If Not IsEmpty(Sheets("DCN Inputs").Range("ProductToggle")) Then
Sheets("DCN Master").Rows("35:74").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
End If
Sheets("Print").Select
On Error Resume Next
Dim obj As Object
Set obj = GetObject(, "Word.Application")
If obj Is Nothing Then
Set obj = CreateObject("Word.Application")
End If
obj.Visible = True
Set objDoc = obj.Documents.Add
a = Sheets("Print").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Print").Range("A1:F" & a).Copy
objDoc.Range.PasteExcelTable False, False, True
objDoc.Activate
Set objTable = objDoc.Tables(1)
With objTable
.AutoFitBehavior wdAutoFitContent
.PreferredWidth = 505
.Range.ParagraphFormat.Alignment = 3
End With
Application.CutCopyMode = False
With objDoc.PageSetup
.TopMargin = Application.InchesToPoints(0.71)
.BottomMargin = Application.InchesToPoints(0.71)
.LeftMargin = Application.InchesToPoints(0.71)
.RightMargin = Application.InchesToPoints(0.71)
End With
With objDoc
.Range.ParagraphFormat.LineSpacingRule = wdLineSpace1pt5
.Range.ParagraphFormat.SpaceAfter = 10
End With
Sheets("DCN Inputs").Select
End Sub
答案 0 :(得分:0)
With objDoc.Range.Tables(1).Range.Cells(1).Range
objDoc.Range(Start:=.Start + 1, _
End:=.Start + 2).Font.ColorIndex = 6
End With
OR
objDoc.Range.Tables(1).Range.Cells(1).Range.Characters(2).Font.ColorIndex = 6