CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2018 开发者帮助

VBE 属性 (ActiveX)

2024-5-18 16:55| 发布者: admin| 查看: 95| 评论: 0|原作者: admin|来自: AutoCAD

VBE 属性 (ActiveX)

获取 VBAIDE 扩展性对象。

支持的平台:仅限 Windows

签名

VBA:

object.VBE
对象

类型: 应用

此属性应用于的对象。

属性值

只读:是的

类型:Microsoft VBE 对象

VBAIDE 扩展性对象。

言论

此特性允许您从AutoCAD的对象模型访问VBA IDE对象模型。如果 VBAIDE 不可用,则该属性将引发异常。例如,如果尚未加载 acvba.arx 应用程序,则 VBAIDE 不可用。

以下代码行返回活动 VBA 项目描述字符串的名称:

ThisDrawing.Application.VBE.ActiveVBProject.Description

例子

VBA:

Sub Example_VBE()
    ' This example uses the VBA IDE extensibility model to dynamically
    ' create a VBA subroutine. After running this example, see the first line of code
    ' in the VBA IDE code window to see a new subroutine. Then 
    ' remove the new subroutine before continuing.

    Dim VBEModel As Object
    Dim newRoutine As String
    
    Set VBEModel = VBE  ' Get the VBE object
    
    ' Define new subroutine to be added. This could be created dynamically from user feedback.
    newRoutine = "Sub Dynamic_Procedure()" & vbCrLf
    newRoutine = newRoutine & vbTab & "MsgBox ""New subroutine.""" & vbCrLf
    newRoutine = newRoutine & "End Sub" & vbCrLf
    
    ' Insert new subroutine
    VBEModel.CodePanes(1).CodeModule.InsertLines 1, newRoutine
    
    MsgBox "A new subroutine was added called Dynamic_Procedure."
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_VBE()
    ;; This example uses the VBA IDE extensibility model to dynamically
    ;; create a VBA subroutine. After running this example, see the first line of code
    ;; in the VBA IDE code window to see a new subroutine. Then 
    ;; remove the new subroutine before continuing.

    ;; Note: You might need to add a code module to the default project first.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    (setq VBEModel (vla-get-VBE acadObj))  ;; Get the VBE object
    
    ;; Define new subroutine to be added. This could be created dynamically from user feedback.
    (setq newRoutine (strcat "Sub Dynamic_Procedure()"
                             "\n    MsgBox \"New subroutine.\""
                             "\nEnd Sub"))
    
    ;; Insert new subroutine
    (vlax-invoke-method (vlax-get-property (vlax-invoke-method (vlax-get-property VBEModel 'CodePanes) 'Item 1) 'CodeModule) 'InsertLines 1 newRoutine)
    
    (alert "A new subroutine was added called Dynamic_Procedure.")
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2025-3-5 17:46

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部