Word 2007 VBA: ActiveDocument.CustomXMLParts

喜欢而已 提交于 2019-12-12 20:02:04

问题


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?


回答1:


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")


来源:https://stackoverflow.com/questions/3144183/word-2007-vba-activedocument-customxmlparts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!