http://support.microsoft.com/kb/181441/zh-tw#top
擷取摘要資訊 WD98: 範例 VBA 程式碼
在 Microsoft Word,您可以使用 Microsoft Visual Basic,應用程式的存取在文件內容
] 對話方塊中,摘要資訊 (檔案] 功能表按 [內容]) 然後在訊息方塊中顯示資訊,將資
訊插入現用文件,或儲存變數中的值。
回此頁最上方
其他相關資訊
Microsoft 會提供不含明示或默示瑕疵責任擔保僅,程式設計的範例。 其中包括,但不
限於) 其適售性或適合某特定用途之默示擔保。 本文假設您已熟悉與程式設計語言,要
示範,以及使用工具來建立和偵錯程序所使用的。 Microsoft 技術支援工程師可以會協
助將說明為特定的程序的功能,但它們就會無法修改這些範例以提供附加功能或建構程序
來滿足您特定需求]。 擷取,或設定在文件屬性] 對話方塊的 [摘要] 索引標籤上的值]
,請使用下列兩個方法使用下列常值 (Literal) 字串引數或屬性的常數。
Literal String Arguments Property Constants
------------------------ ------------------
Title wdPropertyTitle
Subject wdPropertySubject
Author wdPropertyAuthor
Manager wdPropertyManager
Company wdPropertyCompany
Category wdPropertyCategory
Keywords wdPropertyKeywords
Comments wdPropertyComments
Hyperlink base wdPropertyHyperlinkbase
回此頁最上方
方法 1: 使用 BuiltInDocumentProperties 屬性
您可以使用 BuiltInDocumentProperties 屬性,設定,並傳回使用中文件的摘要資訊。
您可以指定要設定或擷取藉由參考透過內建常數或常值 (Literal) 字串引數的值。 下列
程式碼範例會使用 wdPropertyTitle 常數,以擷取使用中文件的標題,並在訊息方塊中
顯示結果。
Sub GetSetDocProps()
If Documents.Count > 0 Then
Dim dp As Object
Set dp = ActiveDocument.BuiltInDocumentProperties
' Retrieve and display the active document's
' title by using the constant "wdPropertyTitle."
MsgBox dp(wdPropertyTitle)
End If
End Sub
下列範例程式碼會使用常值 (Literal) 字串,來定義現用文件的關鍵字:
Sub SetDocProps()
If Documents.Count > 0 Then
Dim dp As Object
Set dp = ActiveDocument.BuiltInDocumentProperties
' Set KeyWords for the active document by
' using a literal string.
dp("KeyWords") = "Summary Information Example Macro"
ActiveDocument.Save
End If
End Sub
回此頁最上方
方法 2: 使用對話方塊集合設定和傳回值
您可以使用對話方塊集合,設定並傳回現用文件的摘要資訊] 的值。
您會傳回,或變更內建對話方塊設定之前,您需要識別個別的對話方塊。 若要這麼做,
使用 [對話方塊集合和 WdWordDialog 常數,用於識別] 對話方塊。 下列 Visual
Basic 陳述式,會傳回對話方塊物件,表示在文件屬性] 對話方塊的 [摘要] 索引標籤。
Set myDialog = Dialogs(wdDialogFileSummaryInfo)
您可以設定或擷取下列的常值 (Literal) 字串引數,而開啟文件時,顯示 [摘要] 索引
標籤。
標題
主旨
作者
管理員
公司
類別
關鍵字
註解
Hyperlinkbase
下列範例巨集會擷取此標題字串的目前值、 放在一個變數的字串的這個值,並設定新值
,而不顯示 [內容] 對話方塊。
Sub SetSummaryInfo()
If Documents.Count > 0 Then
Dim dp As Object
Set dp = Dialogs(wdDialogFileSummaryInfo)
' Retrieve value of Title and store in a variable.
a$ = dp.Title
' Set Title to a new value.
dp.Title = "My Title"
' Set the value without showing the dialog box.
dp.Execute
' Save the changes.
ActiveDocument.Save
End If
End Sub
下列範例巨集的標題設定新值,並顯示 [內容] 對話方塊。
Sub SetSummaryInfo()
If Documents.Count > 0 Then
Dim dp As Object
Set dp = Dialogs(wdDialogFileSummaryInfo)
' Set Title to a new value.
dp.Title = "My Title"
' Set the value.
dp.Execute
' Save the changes.
ActiveDocument.Save
' Display the dialog box.
' Note: Using the Display method will not keep changes
' manually entered into the dialog box. To keep changes
' manually entered in the dialog box, use the Show method.
dp.Display
End If
End Sub
如需詳細資訊請參閱 「 Microsoft 知識庫 」 中的下列文件:
173707 OFF97: 如何從知識庫 」 文件中執行範例程式碼
回此頁最上方
参考
顯示、 設定,或擷取值,在 Word] 對話方塊的相關資訊,按一下 [Office 小幫手時在
Visual Basic 編輯器,"顯示對話方塊"(不含引號) 的型別]、 [搜尋,然後按一下 [顯
示內建 Word 對話方塊]。
如需取得 Visual Basic for Applications 說明的請參閱 「 Microsoft 知識庫 」 中
的下列文件:
163435 VBA: 資源 Visual Basic 設計應用程式