DLL封装的自定义菜单怎样调用宏
请教各位老师在用DLL封装自定义菜单代码中怎样调用另一个宏怎么上传附件呢
1.rar
(35.17 KB)
[[it] 本帖最后由 sdhtli 于 2008-10-16 09:13 编辑 [/it]]
Private JXMBAR As Object Private WithEvents Caishan As Sub Class_Initialize() Dim WJT As Object On Error Resume Next Set WJT = GetObject(, "Excel.Application") Dim JXMBAR As If WJT Is Nothing Then MsgBox "获取Application对象出错!" Else For Each JXMBAR In JXMBAR.Name = "望江婷的工具" Then ("望江婷的工具").Delete Next (Name:="望江婷的工具").Visible = True ("望江婷的工具").Position = msoBarTop Set Caishan = ("望江婷的工具").Controls.Add(Type:=msoControlButton) With Caishan .BeginGroup = True '分隔线 .Caption = "删除数据(&D)" .FaceId = 9404 .Style = msoButtonIconAndCaptionBelow .ToolTipText = "删除当前工作表的数据" End With End If End Sub Private Sub Class_Terminate() On Error Resume Next JXMBAR.Delete End Sub Private Sub Caishan_Click(ByVal Ctrl As , CancelDefault As Boolean) Dim xlapp As Object, xlbok As Object, xlsht1 As Object On Error Resume Next Set xlapp = GetObject(, "Excel.Application") '取得Excel实例[/color] Set xlbok = xlapp.ActiveWorkbook '取得Excel实例下活动工作簿[/color] If MsgBox("确实要清除现有的数据,重新使用吗?", vbInformation + vbYesNo, "警告") = vbYes Then xlbok.Sheets("收支").Range("A3:E65536").Formula = "" End Sub
'对了,把你的Excel中的程序也要修改一下。改成下面的就行了。 Private QQQ As Object Private Sub Workbook_BeforeClose(Cancel As Boolean) '代码注册 Set QQQ = Nothing Shell "Regsvr32 /u /s " & Chr(34) & ThisWorkbook.Path & "\caidan.dll" & VBA.Chr(34), vbHide End Sub Private Sub Workbook_Open() '代码引用 Shell "Regsvr32 /s " & Chr(34) & ThisWorkbook.Path & "\caidan.dll" & VBA.Chr(34), vbHide Set QQQ = New yyy End Sub Private Sub Workbook_Deactivate() On Error Resume Next ("望江婷的工具").Delete End Sub