Word VBA/マクロ 備忘録

作業効率化のため作成したマクロをバックアップ代わりにアップしていきます。

【Word VBA/マクロ】ドキュメントプロパティの全項目を取得

サンプルコードでできること

ドキュメントプロパティの全ての項目を新規文書に書き出します。

Sub ドキュメントプロパティ取得()
    Dim docTo As Document, docProp As DocumentProperty

    Set docTo = Documents.Add '書き出し用のファイル

    On Error Resume Next
        For Each docProp In ActiveDocument.BuiltInDocumentProperties
            Selection.InsertAfter docProp.Name & ": " & _
            docProp.Value & vbCrLf
        Next
    Selection.StartOf wdStory, wdMove ’文書先頭へ移動
End Sub

コードの説明

ActiveDocument.BuiltInDocumentPropertiesで、DocumentPropertiesオブジェクトを取得。
For Eachでタイトル、作成者など、DocumentPropertyオブジェクトの値を取得して、新規文書に書き出します。