[英]how to create a table in a word 2003 document using VBA
我有一個需要填寫的報告模板,我正在自動化這個過程。
模板的一部分向下幾頁,其中有多個相同的表格來輸入數據。
我想要做的是有一個帶有文本框的用戶控件,用戶可以在其中輸入一個數字,然后文檔生成指定的表格數量。
我不確定從哪里開始以及如何指定與文檔的 rest 相關的表格的生成位置,
通過宏記錄器創建基本代碼,然后添加變量和循環:
Sub tableMake()
Dim numberOfTables As Integer
Dim iCount As Integer
numberOfTables = InputBox("How many tables to make?", "Tables")
For iCount = 0 To numberOfTables - 1
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
'.ApplyStyleRowBands = True 'Office 2010
'.ApplyStyleColumnBands = False 'Office 2007
End With
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Next iCount
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.