設定Word表格的VBA代碼

來源:互聯網
上載者:User

   VBA代碼設定Word表格屬性。

  Dim i As Table, N As Integer

  On Error Resume Next ’忽略錯誤

  Application.ScreenUpdating = False ’關閉螢幕更新

  For Each i In ActiveDocument.Tables ’在表格中迴圈

  With i

  .Style = "列表型 4" ’將所有表格設定為"列表型4"的樣式

  With .Borders ‘邊框

  .InsideLineStyle = wdLineStyleSingle ’設定內部邊框線條

  End With

  With .Rows(1).Borders(wdBorderBottom) ‘第一行的底邊框

  .LineStyle = wdLineStyleDouble ‘雙線型

  .LineWidth = wdLineWidth050pt

  .Color = wdColorAutomatic

  End With

  If .Rows.Count > 1 Then ’ 如果表格行數大於1

  If Len(.Cell(2, 1).Range) <= 2 Then ’如果第二行第一列不為空白

  With .Rows(2).Shading ’設定底紋

  .Texture = wdTextureNone ’無底底紋

  .ForegroundPatternColor = wdColorAutomatic

  .BackgroundPatternColor = wdColorGray125

  End With

  End If

  End If

  For N = 2 To .Columns.Count ’從第二列到最後一列

  .Columns(N).Select ’儲存格對齊為中部置中

  Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

  Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter

  Next N

  End With

  Next i

  Application.ScreenUpdating = True

  以上的代碼功能為:表格集合中的迴圈與對儲存格邊框的設定。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.