次の方法で共有


XMLMapping.SetMappingByNode メソッド (Word)

作成するか、コンテンツ コントロールの XML データ マッピングを変更することができます。 Microsoft Word がコンテンツ コントロールをドキュメントのカスタム XML データ ストア内のカスタム XML ノードにマップする場合は True を 返します。

構文

SetMappingByNode( _Node_ )

'XMLMapping' オブジェクトを返す式。

パラメーター

名前 必須 / オプション データ型 説明
ノード 必須 CustomXMLNode 現在のコンテンツ コントロールをマップする XML ノードを指定します。

戻り値

Boolean

注釈

XML マッピングが既に存在する場合、既存の XML マッピングは置き換えられ、コンテンツ コントロールの文字列は新しくマップされた XML ノードの内容に置き換えられます。 SetMapping メソッドも参照してください。

注:

リッチ テキスト コンテンツ コントロールのマッピングを作成すると、実行時エラーが発生します。

次の使用例は、文書の作成者に関する組み込みの文書プロパティを設定し、作業中の文書に新しいコンテンツ コントロールを挿入した後、組み込みの文書プロパティへのコントロールの XML マッピングを設定します。

Dim objcc As ContentControl 
Dim objNode As CustomXMLNode 
Dim objMap As XMLMapping 
Dim blnMap As Boolean 
 
ActiveDocument.BuiltInDocumentProperties("Author").Value = "David Jaffe" 
 
Set objcc = ActiveDocument.ContentControls.Add _ 
 (wdContentControlDate, ActiveDocument.Paragraphs(1).Range) 
 
Set objNode = ActiveDocument.CustomXMLParts.SelectByNamespace _ 
 ("https://schemas.openxmlformats.org/package/2006/metadata/core-properties") _ 
 (1).DocumentElement.ChildNodes(1) 
 
Set objMap = objcc.XMLMapping 
blnMap = objMap.SetMappingByNode(objNode)

次の使用例は、カスタム XML 部分を作成した後、2 つのコンテンツ コントロールを作成し、各コンテンツ コントロールをカスタム XML 内の特定のノードにマップします。

Dim objRange As Range 
Dim objCustomPart As CustomXMLPart 
Dim objCustomControl As ContentControl 
Dim objCustomNode As CustomXMLNode 
 
Set objCustomPart = ActiveDocument.CustomXMLParts.Add 
objCustomPart.LoadXML ("<books><book><author>Matt Hink</author>" & _ 
 "<title>Migration Paths of the Red Breasted Robin</title><genre>non-fiction</genre>" & _ 
 "<price>29.95</price><pub_date>2007-02-01</pub_date><abstract>" & _ 
 "You see them in the spring outside your windows. You hear their lovely " & _ 
 "songs wafting in the warm spring air. Now follow the path of the red breasted robin " & _ 
 "as it migrates to warmer climes in the fall, and then back to your back yard " & _ 
 "in the spring.</abstract></book></books>") 
 
ActiveDocument.Range.InsertParagraphBefore 
Set objRange = ActiveDocument.Paragraphs(1).Range 
Set objCustomNode = objCustomPart.SelectSingleNode _ 
 ("/books/book/title") 
Set objCustomControl = ActiveDocument.ContentControls _ 
 .Add(wdContentControlText, objRange) 
objCustomControl.XMLMapping.SetMappingByNode objCustomNode 
 
objRange.InsertParagraphAfter 
Set objRange = ActiveDocument.Paragraphs(2).Range 
Set objCustomNode = objCustomPart.SelectSingleNode _ 
 ("/books/book/abstract") 
Set objCustomControl = ActiveDocument.ContentControls _ 
 .Add(wdContentControlText, objRange) 
objCustomControl.XMLMapping.SetMappingByNode objCustomNode

関連項目

XMLMapping オブジェクト

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。