当前位置:编程学习 > VB >>

VB6.0为Word2007编写插件,编译报错

原码如下:  

Implements IDTExtensibility2
'Global object references
Public appHostApp As Word.Application

Private WithEvents cbbButton As Office.CommandBarButton

Private Sub cbbButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)

Shell App.Path & "\sys.exe", 1

End Sub

Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)

End Sub

Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)

End Sub

Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
Dim mybar As Office.CommandBar
For Each mybar In Word.Application.CommandBars
    If mybar.Name = "GreetingBar" Then
       mybar.Delete
    End If
Next
' 存储启动引用
Set appHostApp = Application
' 添加命令条
Set cbbButton = CreateBar()
End Sub

Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
RemoveToolbar
' 移除要关闭的引用
Set appHostApp = Nothing
Set cbbButton = Nothing
End Sub

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)

End Sub
Public Function CreateBar() As Office.CommandBarButton
' 指定命令条
Dim cbcMyBar As Office.CommandBar
Dim btnMyButton As Office.CommandBarButton
On Error GoTo CreateBar_Err
Set cbcMyBar = appHostApp.CommandBars.Add(Name:="GreetingBar", Position:=msoBarTop, Temporary:=False)
' 指定命令条按钮
Set btnMyButton = cbcMyBar.Controls.Add(Type:=msoControlButton, Parameter:="Greetings")

With btnMyButton
.Style = msoButtonPicture
.BeginGroup = True
.Picture = LoadPicture(App.Path & "\pic_1.gif")   '注意要相对路径引用
.ToolTipText = "sys"
.Width = "24"
End With
' 显示并返回命令条
cbcMyBar.Visible = True
Set CreateBar = btnMyButton
Exit Function
CreateBar_Err:
MsgBox Err.Number & vbCrLf & Err.Description
End Function
Private Function RemoveToolbar()
Set appHostApp = Application
appHostApp.CommandBars("GreetingBar").Delete
End Function

编译时,说Compile error: Object does not source automation events,并把"WithEvents cbbButton As Office.CommandBarButton"标亮

不知道什么原因,望指点.
--------------------编程问答-------------------- 自己清楚了 --------------------编程问答-------------------- 看不懂啊 --------------------编程问答--------------------
补充:VB ,  基础类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,