关于VBA,涉及到autocad的二次开发,可能涉及到Excel,高分,高手进
我的代码如下-------------------------------------------------------------SubAcadStartup()Ca...
我的代码如下
-------------------------------------------------------------
Sub AcadStartup()
Call InsertMenu
End Sub
Sub InsertMenu()
' 查找是否存在相同菜单,有则删除原有菜单
Dim menuNames As String
Dim menuCollection As AcadPopupMenus
Dim menu As AcadPopupMenu
Set menuCollection = ThisDrawing.Application.MenuGroups.Item(0).Menus
menuNames = ""
For Each menu In menuCollection
menuNames = menu.Name
If menuNames = "组合夹具" Then
On Error Resume Next
menu.RemoveFromMenuBar
End If
Next menu
' 定义当前菜单组的变量
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
' 创建新菜单
Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add("组合夹具")
' 声明表示菜单项的变量
Dim newMenuItem1 As AcadPopupMenuItem
Dim newMenuItem2 As AcadPopupMenuItem
Dim newMenuItem3 As AcadPopupMenuItem
Dim newMenuItem4 As AcadPopupMenuItem
Dim newMenuItem5 As AcadPopupMenuItem
Dim newMenuItem6 As AcadPopupMenuItem
' 并创建菜单项
Set newMenuItem1 = newMenu.AddMenuItem(newMenu.Count + 1, "基础件", "-VBARUN Form1" & vbCr) '将菜单与宏对应
Set newMenuItem2 = newMenu.AddMenuItem(newMenu.Count + 2, "支承件", "-VBARUN Form1" & vbCr)
Set newMenuItem3 = newMenu.AddMenuItem(newMenu.Count + 3, "定位件", "-VBARUN Form1" & vbCr)
Set newMenuItem4 = newMenu.AddMenuItem(newMenu.Count + 4, "导向件", "-VBARUN Form1" & vbCr)
Set newMenuItem5 = newMenu.AddMenuItem(newMenu.Count + 5, "压紧件", "-VBARUN Form1" & vbCr)
Set newMenuItem6 = newMenu.AddMenuItem(newMenu.Count + 6, "紧固件", "-VBARUN Form1" & vbCr)
' 在菜单栏上显示菜单
On Error Resume Next
currMenuGroup.Menus.InsertMenuInMenuBar "组合夹具", ""
End Sub
Sub Form1()
End Sub
-----------------------------------------------------------------
最后一个过程中,我想达到的效果是,让我自己设计的窗体出现,并且这个窗体的caption 值等于我选择的菜单项的名字。比如我选择了“基础件”,那当我选择了基础件的菜单后,FORM1的出现,并且caption的值是“基础件” 展开
-------------------------------------------------------------
Sub AcadStartup()
Call InsertMenu
End Sub
Sub InsertMenu()
' 查找是否存在相同菜单,有则删除原有菜单
Dim menuNames As String
Dim menuCollection As AcadPopupMenus
Dim menu As AcadPopupMenu
Set menuCollection = ThisDrawing.Application.MenuGroups.Item(0).Menus
menuNames = ""
For Each menu In menuCollection
menuNames = menu.Name
If menuNames = "组合夹具" Then
On Error Resume Next
menu.RemoveFromMenuBar
End If
Next menu
' 定义当前菜单组的变量
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
' 创建新菜单
Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add("组合夹具")
' 声明表示菜单项的变量
Dim newMenuItem1 As AcadPopupMenuItem
Dim newMenuItem2 As AcadPopupMenuItem
Dim newMenuItem3 As AcadPopupMenuItem
Dim newMenuItem4 As AcadPopupMenuItem
Dim newMenuItem5 As AcadPopupMenuItem
Dim newMenuItem6 As AcadPopupMenuItem
' 并创建菜单项
Set newMenuItem1 = newMenu.AddMenuItem(newMenu.Count + 1, "基础件", "-VBARUN Form1" & vbCr) '将菜单与宏对应
Set newMenuItem2 = newMenu.AddMenuItem(newMenu.Count + 2, "支承件", "-VBARUN Form1" & vbCr)
Set newMenuItem3 = newMenu.AddMenuItem(newMenu.Count + 3, "定位件", "-VBARUN Form1" & vbCr)
Set newMenuItem4 = newMenu.AddMenuItem(newMenu.Count + 4, "导向件", "-VBARUN Form1" & vbCr)
Set newMenuItem5 = newMenu.AddMenuItem(newMenu.Count + 5, "压紧件", "-VBARUN Form1" & vbCr)
Set newMenuItem6 = newMenu.AddMenuItem(newMenu.Count + 6, "紧固件", "-VBARUN Form1" & vbCr)
' 在菜单栏上显示菜单
On Error Resume Next
currMenuGroup.Menus.InsertMenuInMenuBar "组合夹具", ""
End Sub
Sub Form1()
End Sub
-----------------------------------------------------------------
最后一个过程中,我想达到的效果是,让我自己设计的窗体出现,并且这个窗体的caption 值等于我选择的菜单项的名字。比如我选择了“基础件”,那当我选择了基础件的菜单后,FORM1的出现,并且caption的值是“基础件” 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询