我想用worddoc.builtInDocumentProperties来设置WORD文档的属性,比如作者,标题等,但不会用这个函数,请高手指点。

解决方案 »

  1.   

    发错版了吧,BuiltInDocumentProperties应该是for VB的吧。You access the DocumentProperties collection by using the BuiltInDocumentProperties and CustomDocumentProperties properties of an Office document. The BuiltInDocumentProperties property returns a collection that contains properties that may apply only to certain Office applications. If you try to return the value of these properties in the wrong context, an error occurs.另外,改属性用CustomDocumentProperties When you programmatically add a custom property to the DocumentProperties collection and the property is linked to a value in the underlying Office document, you must use the document's Save method, as illustrated above, before the property value will be correctly reflected for the new DocumentProperty object.The following procedure illustrates how to add both static and linked custom properties to the DocumentProperties collection. It is essentially a wrapper around the Add method of the DocumentProperties collection that includes parameter validation and deletes any existing custom property before adding a property that uses the same name.Function AddCustomDocumentProperty(strPropName As String, _
                                     lngPropType As Long, _
                                     Optional varPropValue As Variant = "", _
                                     Optional blnLinkToContent As Boolean = False, _
                                     Optional varLinkSource As Variant = "") _
                                     As Long
                             
       ' This procedure adds the custom property specified in the strPropName
       ' argument. If the blnLinkToContent argument is True, the custom
       ' property is linked to the location specified by varLinkSource.
       ' The procedure first checks for missing or inconsistent input parameters.
       ' For example, a value must be provided unless the property is linked, and
       ' when you are using linked properties, the source of the link must be provided.   Dim prpDocProp As DocumentProperty
       
       ' Validate data supplied in arguments to this procedure.
       If blnLinkToContent = False And Len(varPropValue) = 0 Then
          ' No value supplied for custom property.
          AddCustomDocumentProperty = ERR_CUSTOM_LINKTOCONTENT_VALUE
          Exit Function
       ElseIf blnLinkToContent = True And Len(varLinkSource) = 0 Then
          ' No source provided for LinkToContent scenario.
          AddCustomDocumentProperty = ERR_CUSTOM_LINKTOCONTENT_LINKSOURCE
          Exit Function
       ElseIf lngPropType < msoPropertyTypeNumber Or _
             lngPropType > msoPropertyTypeFloat Then
          ' Invalid value for data type specifier. Must be one of the
          ' msoDocProperties enumerated constants.
          AddCustomDocumentProperty = ERR_CUSTOM_INVALID_DATATYPE
          Exit Function
       ElseIf Len(strPropName) = 0 Then
          ' No name supplied for new custom property.
          AddCustomDocumentProperty = ERR_CUSTOM_INVALID_PROPNAME
          Exit Function
       End If
       
       Call DeleteIfExisting(strPropName)   Select Case blnLinkToContent
          Case True
             Set prpDocProp = ActiveWorkbook.CustomDocumentProperties _
                .Add(Name:=strPropName, LinkToContent:=blnLinkToContent, _
                Type:=lngPropType, LinkSource:=varLinkSource)
                ActiveWorkbook.Save
          Case False
             Set prpDocProp = ActiveWorkbook.CustomDocumentProperties. _
                Add(Name:=strPropName, LinkToContent:=blnLinkToContent, _
                Type:=lngPropType, Value:=varPropValue)
       End Select
    End Function
      

  2.   

    只有对下列属性才可以用BuiltInDocumentProperties设置属性
    Title, Subject, Author, Keywords, Comments, Template, Last Author, 
    Revision Number, Application Name, Last Print Date, Creation Date, 
    Last Save Time, Total Editing Time, Number of Pages, Number of Words, 
    Number of Characters, Security, Category, Format, Manager, Company,
    Number of Bytes, Number of Lines, Number of Paragraphs, Number of Slides, Number of Notes, Number of Hidden Slides, Number of Multimedia Clips, Hyperlink Base, Number of Characters (with spaces)比如,改作者:
    ActiveDocument.BuiltInDocumentProperties(wdPropertyAuthor) = "L291118 (L291118)"
      

  3.   

    那样在VB中没问题可在DELPHI 中不行,因为在DELPHI中,ActiveDocument.BuiltInDocumentProperties是一个接口类IDispatch,而这个接口类不知怎么用!