使用vba更改字表中特定单元格的颜色和字体

Kaz*_*uri 12 vba ms-word word-vba

我正在尝试在文档末尾设置一个新表格并将其格式化为我的规范.但backgroundcolor和textcolor似乎不起作用.字体大小也不是我想要的,因为它适用于整个表而不仅仅是一个单元格.

这是我到目前为止:

Dim myRange As Object
Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseEnd
ActiveDocument.Tables.Add Range:=myRange, NumRows:=3, NumColumns:=2
With .Tables(.Tables.Count)
    .Cell(1, 1).Select
    With Selection
        .Shading.Texture = wdTextureNone
        .Shading.ForegroundPatternColor = wdColorWhite
        .Shading.BackgroundPatternColor = wdColorGray25
        .Font.Size = 14
        .Font.Bold = True
        .Text = "Hello World"
    End With
End With
Run Code Online (Sandbox Code Playgroud)

我希望表格的第一行没有边框,灰色背景上的字体为14,粗体,白色文字.

Kaz*_*uri 12

我找到了答案.

解决方案如下:

With .Tables(.Tables.Count)        
    With .Cell(1, 1)
        .Shading.BackgroundPatternColor = wdColorGray50
        With .Range
            With .Font 
                .TextColor = wdColorWhite
                .Size = 18
                .Bold = True
            End With
            .Text = "Hello World"
        End With
    End With            
End With
Run Code Online (Sandbox Code Playgroud)

我删除了单元格的选择并直接使用它.但真实的是,应用.Range时的使用.Font.Text