Word VBA-表格操作汇总
生活随笔
收集整理的這篇文章主要介紹了
Word VBA-表格操作汇总
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
===========================
Sub 遍歷表格設定樣式()For Each aTable In ActiveDocument.TablesWith aTableWith .Shading.Texture = wdTextureNone.ForegroundPatternColor = wdColorAutomatic.BackgroundPatternColor = wdColorAutomaticEnd WithWith .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle.LineWidth = wdLineWidth050pt.Color = wdColorAutomaticEnd WithWith .Borders(wdBorderRight).LineStyle = wdLineStyleSingle.LineWidth = wdLineWidth050pt.Color = wdColorAutomaticEnd WithWith .Borders(wdBorderTop).LineStyle = wdLineStyleSingle.LineWidth = wdLineWidth050pt.Color = wdColorAutomaticEnd WithWith .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle.LineWidth = wdLineWidth050pt.Color = wdColorAutomaticEnd WithWith .Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle.LineWidth = wdLineWidth050pt.Color = wdColorAutomaticEnd WithWith .Borders(wdBorderVertical).LineStyle = wdLineStyleSingle.LineWidth = wdLineWidth050pt.Color = wdColorAutomaticEnd With.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone.Borders.Shadow = FalseEnd WithWith Options.DefaultBorderLineStyle = wdLineStyleSingle.DefaultBorderLineWidth = wdLineWidth050pt.DefaultBorderColor = wdColorAutomaticEnd WithNext aTable End Sub===========================
'遍歷表格的操作Dim aTable As Table'第一種實現方式,根據索引遍歷表格,特定單元格賦值內容For i = 1 To ActiveDocument.Tables.CountSet aTable = ActiveDocument.Tables.Item(i)With aTable.Cell(2, 1).Range.Text = "123"End WithNext'第二種實現方式For Each aTable In ActiveDocument.TablesWith aTable.Cell(2, 1).Range.Text = "123"End WithNext===========================
'判斷表格列標題,針對不同標題列設置不同樣式 With aTableFor i = 1 To .Columns.CountIf InStr(.Cell(1, i).Range.Text, "序號") Or _InStr(.Cell(1, i).Range.Text, "數量") Or _InStr(.Cell(1, i).Range.Text, "單位") Then(Code代碼段)End IfNext End With===========================
'表格樣式設置代碼匯總 With aTable'將預定義外觀應用于表格。' .AutoFormat Format:=wdTableFormatColorful2' .AutoFormat applyborders:=True' .AutoFormat ApplyShading:=True' .AutoFormat ApplyFont:=True' .AutoFormat ApplyColor:=True' .AutoFormat ApplyHeadingRows:=True' .AutoFormat ApplyLastRow:=True' .AutoFormat ApplyFirstColumn:=True' .AutoFormat ApplyLastColumn:=True' .AutoFormat AutoFit:=True'應用用戶定義的樣式,但保留用戶直接應用的所有格式。' .ApplyStyleDirectFormatting StyleName:="樣式1"'調整行列的樣式,必須使用Select的方法,先選中再設置樣式'調整首行的對齊方式' .Rows(1).Select' With Selection' .ParagraphFormat.Alignment = wdAlignParagraphCenter' End With'調整各列的對齊方式' .Columns(3).Select' With Selection' .ParagraphFormat.Alignment = wdAlignParagraphCenter' End With' .Columns(4).Select' With Selection' .ParagraphFormat.Alignment = wdAlignParagraphCenter' End With'操作單元格內容賦值' .Cell(1, 1).Range.Text = "hello"End With===========================
===========================
===========================
===========================
===========================
===========================
===========================
===========================
===========================
===========================
===========================
===========================
===========================
===========================
?
總結
以上是生活随笔為你收集整理的Word VBA-表格操作汇总的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2009程序员考试大纲
- 下一篇: Snake算法知识点记录