[英]How to update a Table of Tables with macro vba-Word?
我是 word-vba 宏的初學者(但我對 excel-vba 非常擅長),我希望更新“表格表”。 我已經找到了如何為“目錄”和“圖表”(使用ActiveDocument.TablesOfContents(1).Update
)執行此操作,但 Collection TableOfTables 不存在。 有人知道我必須做什么嗎?
提前致謝,
沒有“Table of Tables”對象或 TableOfTables 集合。 “Table of Tables”實際上只是一種“目錄”。 事實上,“圖表”也是如此。 如果您查看這些代碼下面的域代碼,您將看到所有三個都使用 TOC 域——“表格表”和“圖表表”的域代碼類似於 { TOC \\h \\z \\c "Table" } 和 { TOC \\h \\z \\c "Figure" },分別。 因此,如果您想更新其中任何一個(或您創建的任何自定義類型),但不一定是全部,您可以簡單地循環遍歷 TableOfContents 集合並檢查 \\c 開關后面的內容(如果存在)。 同樣,您可以遍歷 TableOfContents 集合並更新其中的所有項目。 因此:
Sub Demo()
Application.ScreenUpdating = False
Dim TOC As TableOfContents
For Each TOC In ActiveDocument.TablesOfContents
TOC.Update
'Or depending on what you want to update:
'TOC.UpdatePageNumbers
Next
Application.ScreenUpdating = True
End Sub
一種更簡單的方法 - 對於所有領域 - 將是:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument
.Fields.Update
.PrintPreview
.ClosePrintPreview
End With
Application.ScreenUpdating = True
End Sub
好的,感謝@macropod,我想出了如何解決我的問題。 “表格”不是另一個目錄,而是另一個數字表格所以這是我的結局代碼:
Public Sub UpdateAllFiles()
With ActiveDocument
.TablesOfContents(1).Update
.TablesOfFigures(1).Update
.TablesOfFigures(2).Update
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.