开发者

Word 2007 VBA: ActiveDocument.CustomXMLParts

开发者 https://www.devze.com 2023-01-05 16:22 出处:网络
In this tutorial (and many others), there\'s an integer in the CustomXMLParts object collection Load method that I can\'t find an explanation for.The Word 2007 VBA Reference开发者_如何转开发 doesn\'t

In this tutorial (and many others), there's an integer in the CustomXMLParts object collection Load method that I can't find an explanation for. The Word 2007 VBA Reference开发者_如何转开发 doesn't seem to list the Load method either:

  ''# Load CustomerData.xml file
  ActiveDocument.CustomXMLParts.Add
  ActiveDocument.CustomXMLParts(4).Load ("c:\CustomerData.xml") 

What does the 4 represent?


There are always three built-in CustomXMLParts in every .docx (created by Word 2007/2010 - not necessarily a .docx created by the Open XML SDK). Namely:

<cp:coreProperties xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"><dc:creator></dc:creator><cp:keywords/><dc:description/><dc:subject/><dc:title/><cp:category/><cp:contentStatus/></cp:coreProperties>

<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"><Company/><Manager/></Properties>

<CoverPageProperties xmlns="http://schemas.microsoft.com/office/2006/coverPageProps"><PublishDate/><Abstract/><CompanyAddress/><CompanyPhone/><CompanyFax/><CompanyEmail/></CoverPageProperties>

So 4 here just means, after you've done ActiveDocument.CustomXMLParts.Add to add a fourth one "get the fourth one". If you had more, you would just use the next available index number. Instead of 4, I'd probably just use this instead:

Dim ap As Document
Set ap = ActiveDocument
ap.CustomXMLParts.Add
ap.CustomXMLParts(ap.CustomXMLParts.Count).Load ("C:\CustomerData.xml")
0

精彩评论

暂无评论...
验证码 换一张
取 消