本文介绍了在VBA中后期绑定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在后期绑定到VBProject对象时遇到运行时错误429"的问题:

I am getting the "run-time error 429" in my attempt at late binding to the VBProject object:

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

有一些我无法理解的基本知识吗?

Is there something fundamental I am failing to understand?

例如,您将如何在第308340条中编写代码以使用后期绑定? :

For example, how would you write the code in article 308340 to use late binding?:

 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

推荐答案

丹尼斯,

如果从Word内部运行此程序,则无需使用CreateObject().

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

设置vbProj = ActiveDocument.VBProject将起作用.

Set vbProj = ActiveDocument.VBProject will work.

如果要从其他地方运行它,则可能需要先创建Word对象并加载文档:

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

在两种情况下,您都可能会获得不信任对Visual Basic项目的编程访问",这可以通过宏安全性设置来解决, http://support.microsoft.com/kb/282830 .

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.

这篇关于在VBA中后期绑定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 04:47