1

我在尝试后期绑定到 VBProject 对象时收到“运行时错误 429”:

Dim vbProj As Object
Set vbProj = CreateObject("ActiveDocument.VBProject")

有什么基本的我无法理解吗?

例如,如何编写文章 308340中的代码来使用后期绑定?:

 Sub CheckReference()

        Dim vbProj As VBProject  
        Set vbProj = ActiveDocument.VBProject

        For Each chkRef In vbProj.References

          If chkRef.IsBroken Then
             Debug.Print chkRef.Name
          End If

        Next

    End Sub
4

2 回答 2

4

Dennis,

if you are running this from within Word, then you don't need to use CreateObject().

Set vbProj = ActiveDocument.VBProject will work.

if you are running this from elsewhere, then you may need to create Word object first and load the document:

  Dim a As Object
  Dim vbProj As Object

  Set a = CreateObject("Word.Application")
  a.Documents.Open "C:\temp\test1.docx"
  MsgBox a.Documents.Count
  Set vbProj = a.ActiveDocument.VBProject

In both cases you may get the "Programmatic Access to Visual Basic Project is not Trusted" which resolves through Macro security settings, http://support.microsoft.com/kb/282830.

I hope this answers your question.

于 2009-12-03T04:43:33.810 回答
0

你是从哪里想出那个 progid (ActiveDocument.VBProject) 的?通常 progid 的格式为 AppName.ObjectName,如 Excel.Sheet 或 Word.Document。IIRC、VB6 本身不支持 OLE 自动化;相反,它支持创建OLE 自动化服务器和客户端。

更新:

好的,我知道现在发生了什么。ActiveDocument.VBProject 不是有效的 progid。ActiveDocument 是 Word.Application 对象的一个​​属性,它的 progid 是(惊喜!)“Word.Application”。

所以你想要 Meringros 的答案。

于 2009-12-02T22:35:33.053 回答