簡體   English   中英

使用vba更改字表中特定單元格的顏色和字體

[英]changing color and font of specific cells in word table with 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

我希望表格的第一行沒有邊框,而灰色背景上的字體為14,粗體,白色文字。

我找到了答案。

解決方案如下:

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

我刪除了單元格的選擇並直接使用它。 但真正的事情是,使用.Range申請時.Font.Text

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM