- UID
- 9121
- 积分
- 142
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-8-24
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2004-7-5 20:51:56
|
显示全部楼层
谢谢,我已经直接通过vba工程解决了,代代码如下:可直接通过菜单加载.
由此可实现多模块动态加载,卸载,并可动态构造菜单
Public Function GetVBAProjFileNames(Optional projName As String = "")
Dim i As Long, projects() As String
Dim objIDE As VBIDE.VBE
Set objIDE = Application.VBE
ReDim projects(0 To objIDE.VBProjects.Count - 1)
For i = 0 To objIDE.VBProjects.Count - 1
projects(i) = objIDE.VBProjects(i + 1).fileName
Next
If projName = "" Then
'未指定则返回全部
GetVBAProjFileNames = projects
Exit Function
Else
'返回特定
Dim length As Long
If Right(projName, 4) <> ".dvb" Then projName = projName & ".DVB"
length = Len(projName)
For i = 0 To objIDE.VBProjects.Count - 1
If Right(projects(i), length) = projName Then
GetVBAProjFileNames = projects(i)
Exit Function
End If
Next
'未找到特定,则返回空
GetVBAProjFileNames = ""
End If
End Function
Sub AddmainMenu()
Dim MenuGroup As AcadMenuGroup
Dim etMainMenu As AcadPopupMenu
Dim menuItem
Set MenuGroup = Application.MenuGroups("ACAD")
On Error Resume Next
Set etMainMenu = MenuGroup.Menus(APPName)
If err.Number = 0 Then
On Error GoTo 0
For Each menuItem In etMainMenu
menuItem.Delete
Next
Else
On Error GoTo 0
Set etMainMenu = MenuGroup.Menus.Add(APPName)
End If
etMainMenu.AddMenuItem 1, "xxxxxxxxxxxx", "-vbarun DoUtility acadet FixLayOutScale" & vbCr
If Not etMainMenu.OnMenuBar Then etMainMenu.InsertInMenuBar Application.MenuBar.Count - 1
End Sub
'主执行模块
Public Sub DoUtility()
Dim strModul As String, strVbaSub As String
strModul = ThisDrawing.Utility.GetString(False)
strVbaSub = ThisDrawing.Utility.GetString(False)
If GetVBAProjFileNames(strModul) = "" Then
'判断模块是否存在,不存在则加载
Application.LoadDVB GetETToolsPath & strModul & ".dvb"
End If
ThisDrawing.SendCommand "-VBARUN" & " " & strVbaSub & vbCrLf
End Sub
Function GetETToolsPath() As String
Static etToolsPath As String
If etToolsPath = "" Then
etToolsPath = GetVBAProjFileNames("ACADET.DVB")
etToolsPath = Left(etToolsPath, Len(etToolsPath) - 10)
End If
GetETToolsPath = etToolsPath
End Function |
|